Skip to contents

Returns 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.

Usage

path_prefix(path, depth = 2)

Arguments

path

Character vector of file paths (relative or absolute)

depth

Integer. Number of leading path components to keep (>= 0)

Value

Character vector of normalized path prefixes

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 depth are returned unchanged

  • depth = 0 returns 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")