Learn R Programming

SpaDES.core (version 3.2.1)

findProjectPath: Find the project root directory

Description

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.

Usage

findProjectPath(path = getwd())

Value

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

Arguments

path

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

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

Run this code
findProjectPath()                 # the project the session is working in
findProjectPath(tempdir())        # no markers above tempdir(); returns it

Run the code above in your browser using DataLab