Skip to contents

Resolves the directory that assets/, reports/ and zip_files/ sit beneath, in this order:

Usage

mariner_project_root(path = ".")

Arguments

path

Directory to search upward from. Defaults to the working directory.

Value

A normalised absolute path.

Details

  1. getOption("mariner.project_root"), if set. The escape hatch for a session whose working directory is not where the reports belong.

  2. path itself, if it holds an .Rproj file, a _quarto.yml, a DESCRIPTION, or all three mariner folders. A project mariner_setup_project() scaffolded is therefore found again without also being an RStudio or Quarto project.

  3. An ancestor carrying one of those, reached by climbing out of assets/, reports/ or zip_files/ – so bundling reports/ch1.qmd resolves to the project that holds reports/.

  4. path itself, normalised.

The walk in step 3 goes through mariner folders and nothing else. A marker in a parent directory does not claim an unrelated subdirectory: run this from project/scratch and you get project/scratch, whatever project carries.

.git is not a marker here, though it is one for mariner_looks_like_project(). See the comment in R/setup.R for why.

A root argument to mariner_dirs() or mariner_setup_project() beats all of them. Those functions call this one only when root is NULL.

Examples

mariner_project_root()
#> [1] "/Users/thomasreinke/Library/CloudStorage/OneDrive-Personal/Personal R Projects/mariner/docs/reference"

# The option wins over the search:
withr::with_options(
  list(mariner.project_root = tempdir()),
  mariner_project_root()
)
#> [1] "/private/var/folders/k3/k8hfzfxd11j6vy0_t2rx27yw0000gn/T/RtmpWsU1oN"