copy a file in r

To copy a file in R, we can use the file.copy() function. This function takes two arguments: the source file name and the destination file name.

Here's an example of how to copy a file in R:

main.r
# Source file name
source_file <- "path/to/source/file.txt"

# Destination file name
dest_file <- "path/to/destination/file.txt"

# Copy the file
file.copy(source_file, dest_file)
180 chars
9 lines

Note that if the destination file already exists, it will be overwritten. If you want to avoid overwriting an existing file, you can use the file.exists() function to check if the file exists before copying:

main.r
if (!file.exists(dest_file)) {
  file.copy(source_file, dest_file)
} else {
  cat("Destination file already exists.")
}
120 chars
6 lines

gistlibby LogSnag