Learn R Programming

⚠️There's a newer version (2.0.4) of this package.Take me there.

rprojroot

This package helps accessing files relative to a project root to stop the working directory insanity. It is a low-level helper package for the here package.

Example

The rprojroot package works best when you have a “project”: all related files contained in a subdirectory that can be categorized using a strict criterion. Let’s create a package for demonstration.

R packages satisfy the is_r_package criterion. A criterion is an object that contains a find_file() function. With pkg as working directory, the function works like file.path(), rooted at the working directory:

This works identically when starting from a subdirectory:

There is one exception: if the first component passed to find_file() is already an absolute path. This allows safely applying this function to paths that may be absolute or relative:

As long as you are sure that your working directory is somewhere inside your project, you can retrieve the project root.

Installation and further reading

Install the package from CRAN:

See the documentation for more detail.


Code of Conduct

Please note that the rprojroot project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Copy Link

Version

Install

install.packages('rprojroot')

Monthly Downloads

518,748

Version

2.0.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Kirill Müller

Last Published

November 15th, 2020

Functions in rprojroot (2.0.2)

thisfile

Determines the path of the currently running script
rprojroot-package

rprojroot: Finding Files in Project Subdirectories
root_criterion

Is a directory the project root?
deprecated

Deprecated functions
criteria

Prespecified criteria
find_root

Find the root of a directory hierarchy
find_root_file

File paths relative to the root of a directory hierarchy