here() uses a reasonable heuristics to find your project's files, based on the current working directory at the time when the package is loaded. Use it as a drop-in replacement for file.path(), it will always locate the files relative to your project root.

dr_here() shows a message that by default also includes the reason why here() is set to a particular directory. Use this function if here() gives unexpected results.

set_here() creates an empty file named .here, by default in the current directory. When here encounters such a file, it uses the directory that contains this file as root. This is useful if none of the default criteria apply. You need to restart the R session so that here() picks up the newly created file.

here(...)

dr_here(show_reason = TRUE)

set_here(path = ".", verbose = TRUE)

Arguments

...

[character]
Path components below the project root, can be empty. Each argument should be a string containing one or more path components separated by a forward slash "/".

show_reason

[logical(1)]
Include reason in output of dr_here(), defaults to TRUE.

path

[character(1)]
Directory where to create .here file, defaults to the current directory.

verbose

[logical(1)]
Verbose output, defaults to TRUE.

Details

This package is intended for interactive use only. Use rprojroot::has_file() or the other functions in the rprojroot package for more control, or for package development.

Project root

Starting with the current working directory during package load time, here will walk the directory hierarchy upwards until it finds a directory that satisfies at least one of the following conditions:

  • contains a file .here

  • contains a file matching [.]Rproj$ with contents matching ^Version: in the first line

  • contains a file DESCRIPTION with contents matching ^Package:

  • contains a file remake.yml

  • contains a file .projectile

  • contains a directory .git

  • contains a file .git with contents matching ^gitdir:

  • contains a directory .svn

Once established, the root directory doesn't change during the active R session. here() then appends the arguments to the root directory.

Examples

here()
#> [1] "/home/travis/build/r-lib/here"
# NOT RUN { here("some", "path", "below", "your", "project", "root.txt") here("some/path/below/your/project/root.txt") # }