
Extract a stable path prefix at a fixed structural depth
path_prefix.RdReturns the first depth components of each path as a normalized
forward-slash-separated prefix. This provides a deterministic and
reproducible way to derive a structural grouping key from file paths.
Details
The function does not interpret paths (e.g. no special handling of filenames, repositories, or working directories). It simply truncates the path at the requested depth after normalizing separators.
Typical use cases include:
grouping files by project or subproject (e.g. depth = 2)
creating stable aggregation units for audit, reporting, or timesheets
deriving Record Set–like groupings in RiC-aligned archival workflows
Behavior is fully deterministic:
identical inputs always produce identical outputs
paths shorter than
depthare returned unchangeddepth = 0returns an empty string (explicit root-level grouping)
Examples
path_prefix("_eviota/reporting/R/scan_storage.R", depth = 2)
#> [1] "_eviota/reporting"
# "_eviota/reporting"
path_prefix(c("a/b/c.txt", "x/y"), depth = 1)
#> [1] "a" "x"
# c("a", "x")