Split a path into directory components
split_path splits a character vector of paths into directory
components. The opposite of
split_dir is a convenience wrapper equivalent to
split_path, making it easy to
split_path(x = dir(), simplify = FALSE)split_dir(x = ".", pattern = NULL, all.files = TRUE, recursive = TRUE, simplify = TRUE)
- A character vector. For
split_path, this should contain file paths, and it defaults to files in the current directory. For
split_dir, this should contain directory paths, and it defaults to the current directory.
- A logical value. If
TRUE, the return value is simplified from a list to a matrix.
- A string containing a regular expression, to filter the files
that are returned. Passed to
- Logical. If
TRUE, files whose name starts with a dot are included. Passed to
- Logical. If
TRUE, files in subdirectories are included. Passed to
Either a named list of character vectors containing the split paths,
or a matrix. See
simplifyargument in Usage section.
Paths are split on forward and back slashes, except for double forward or back slashes at the start of (UNC) paths. These are included in the first element of that split path.
(splits <- split_path(c(getwd(), "~", r_home()))) # Reverse the operation sapply(splits, paste, collapse = "/") base_r_files <- split_dir(R.home(), pattern = "\\.R$") # Viewing not needed for testing purposes utils::View(base_r_files)