Small helpers: file-path parts with get_path_info(), and
the example files shipped with the package.
get_path_info()paths <- c("C:/Users/foo/Documents/report.xlsx",
"/home/user/.bashrc",
"relative/path/to/data.csv",
".hidden.tar.gz",
NA_character_)
# Mode B: filename only, extension stripped (default)
get_path_info(paths)
#> [1] "report" ".bashrc" "data" ".hidden.tar" NA
# Mode B: filename only, extension preserved
get_path_info(paths, rm_extension = FALSE)
#> [1] "report.xlsx" ".bashrc" "data.csv" ".hidden.tar.gz"
#> [5] NA
# Mode B: full normalised path, extension stripped
get_path_info(paths, rm_path = FALSE)
#> [1] "C:/Users/foo/Documents/report" "/home/user/.bashrc"
#> [3] "relative/path/to/data" ".hidden.tar"
#> [5] NA
# Mode A: extract the 2nd path segment
get_path_info(paths, n = 2)
#> [1] "foo" "user" "path" NA NA
# Mode A: extract the last segment with extension stripped (n = -1 linkage)
get_path_info(paths, n = -1, rm_extension = TRUE)
#> [1] "report" ".bashrc" "data" ".hidden.tar" NA
# Mode A: range extraction
get_path_info(paths, n = c(2, 3))
#> [1] "foo/Documents" "user/.bashrc" "path/to" NA
#> [5] NAmintyr_example()