This function is designed to use the Unix cp command, but will revert to base::file.copy() in Windows environments. In this case, including "-r" in args results in recursive = TRUE.

file_copy(from, to, args = c("-p", "-r"))

Arguments

from

character vector containing file names or paths. Can also contain directories, but args must include "-r" (recursive).

to

character vector containing file names, paths, or existing directories.

args

character vector of additional arguments to cp. The default includes "-p", to preserve mode, ownership, and timestamps; and "-r" to copy directories recursively. See file_copy(args = "help") for cp arguments.

Value

returns a logical vector indicating which copy operations succeeded for each of the files attempted.

Examples

if (FALSE) { # \dontrun{
# Get cp help to review optional args
file_copy(args = "help")

# Copy a single file
file_copy("old-dir/file.R", "new-dir/file.R")

# Copy multiple files to an existing directory
file_copy(c("old-dir/file1.R", "old-dir/file2.R"), "new-dir/")

# Pass no optional arguments
file_copy("old-dir/file.R", "new-dir/file.R", args = NULL)

# Pass optional arguments
file_copy("old-dir/file.R", "new-dir/file.R", args = c("-b", "-n", "-p"))
} # }