Searches upward from path for an RStudio project file (a .Rproj whose first line is Version: ) or a git repository (a .git directory, or a .git file pointing elsewhere, as used by worktrees and submodules), falling back on path itself when neither is found.

findProjectPath(path = getwd())

Arguments

path

The directory to search upward from. Defaults to getwd().

Value

An absolute path to the project root, or path if no project marker is found above it.

Details

This uses rprojroot when it is available. rprojroot is in Suggests, so when it is not installed this simply returns path, which is the same answer the fallback gives.

Examples

findProjectPath()                 # the project the session is working in
#> [1] "/home/runner/work/SpaDES.core/SpaDES.core"
findProjectPath(tempdir())        # no markers above tempdir(); returns it
#> [1] "/tmp/RtmpmM1qrr"