copy a directory in r

To copy a directory in R, we can use the file.copy() function that copies one or more files from one location to another. To copy a directory, we need to specify the source directory and the destination directory.

Here's a sample code snippet that copies an entire directory:

main.r
# Set the source directory
src_dir <- "/path/to/source/directory"

# Set the destination directory
dest_dir <- "/path/to/destination/directory"

# Copy the source directory to the destination directory
file.copy(from = src_dir, to = dest_dir, recursive = TRUE)
261 chars
9 lines

The file.copy() function copies the directory recursively, which means it copies all the subdirectories and files within the source directory. The recursive argument in the function specifies whether to copy the directory and its contents recursively or not.

Note that if the destination directory already exists, the file.copy() function will overwrite the existing directory and its contents.

gistlibby LogSnag