Learn R Programming

pathological (version 0.1-1)

split_path: Split a path into directory components

Description

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. For split_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 to dir.
recursive
Logical. If TRUE, files in subdirectories are included. Passed to dir.

Value

Either a named list of character vectors containing the split paths, or a matrix. See simplify argument in Usage section.

See Also

file.path, dir

Examples

Run this code
(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)

Run the code above in your browser using DataLab