This helper starts from a directory and walks upward until it finds a directory that contains all requested marker files or directories. It is used by post-assessment scripts to locate a project root without depending on a fixed working directory.

find_project_root(
  path = getwd(),
  markers = "future_outputs",
  winslash = "/",
  mustWork = TRUE
)

Arguments

path

Character scalar. Directory to start searching from. Defaults to the current working directory.

markers

Character vector. File or directory names that must exist directly under the project root.

winslash

Character scalar passed to [normalizePath()] on Windows.

mustWork

Logical. If `TRUE`, throw an error when no matching parent directory is found. If `FALSE`, return `NA_character_`.

Value

A normalized path to the first parent directory containing all `markers`, or `NA_character_` when `mustWork = FALSE` and no root is found.

Examples

if (FALSE) { # \dontrun{
find_project_root(markers = "future_outputs")
} # }