split_path
From pathological v0.1-1
by Richard Cotton
Split a path into directory components
split_path
splits a character vector of paths into directory
components. The opposite of file.path
.
split_dir
is a convenience wrapper equivalent to dir
+
split_path
, making it easy to View
directory
contents.
Usage
split_path(x = dir(), simplify = FALSE)
split_dir(x = ".", pattern = NULL, all.files = TRUE, recursive = TRUE, simplify = TRUE)
Arguments
- x
- A character vector. For
split_path
, this should contain file paths, and it defaults to files in the current directory. Forsplit_dir
, this should contain directory paths, and it defaults to the current directory. - simplify
- A logical value. If
TRUE
, the return value is simplified from a list to a matrix. - pattern
- A string containing a regular expression, to filter the files
that are returned. Passed to
dir
. - all.files
- Logical. If
TRUE
, files whose name starts with a dot are included. Passed todir
. - recursive
- Logical. If
TRUE
, files in subdirectories are included. Passed todir
.
Value
-
Either a named list of character vectors containing the split paths,
or a matrix. See
simplify
argument in Usage section.
Note
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.
See Also
Examples
(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)
Community examples
Looks like there are no examples yet.