Variables in Crunch datasets are organized into folders, like in a file system. Datasets are similarly organized into hierarchical Projects. These functions allow you to create new folders and move objects into folders. Their names, mv and mkdir, suggest their Unix file utility inspiration.

mv(x, what, path)

mkdir(x, path)

Arguments

x A CrunchDataset or Folder (VariableFolder or ProjectFolder) A Variable, selection of variables from dataset, or any other object that can be moved to a folder (e.g. a dataset when organizing projects). A character "path" to the folder: either a vector of nested folder names or a single string with nested folders separated by a delimiter ("/" default, configurable via options(crunch.delimiter)). The path is interpreted as relative to the location of the folder x (when x is a dataset, that means the root, top-level folder). path may also be a Folder object.

Value

x, with the folder at path guaranteed to be created, and for mv, containing what moved into it.

Details

The functions have some differences from the strict behavior of their Unix ancestors. For one, they work recursively, without additional arguments: mkdir will make every directory necessary to construct the requested path, even if all parent directories didn't already exist; and mv doesn't require that the directory to move to already exist---it will effectively call mkdir along the way.

cd() to select a folder by path; rmdir() to delete a folder; folder() to identify and set an object's parent folder; base::dir.create() if you literally want to create a directory in your local file system, which mkdir() does not do

Examples

if (FALSE) {
ds <- mv(ds, c("gender", "age", "educ"), "Demographics")
ds <- mkdir(ds, "Key Performance Indicators/Brand X")
# These can also be chained together
require(magrittr)
ds <- ds %>%
mv(c("aware_x", "nps_x"), "Key Performance Indicators/Brand X") %>%
mv(c("aware_y", "nps_y"), "Key Performance Indicators/Brand Y")
# Can combine with cd() and move things with relative paths
ds %>%
cd("Key Performance Indicators/Brand X") %>%
mv("nps_x", "../Net Promoters")
# Can combine with folder() to move objects to the same place as something else
ds %>% mv("nps_y", folder(ds\$nps_x))
# Now let's put ds in a Project
projects() %>%
mv(ds, "Brand Tracking Studies")
}