To move a CSV file in R, you can make use of the file.copy()
function. This function can be used to copy files from one directory to another.
Here's an example code to move a CSV file named "data.csv" from its original location (e.g., "C:/Users/username/Documents/") to a new location (e.g., "C:/Users/username/Desktop/"):
main.r228 chars7 lines
This code will copy the "data.csv" file from the original directory to the new directory, and overwrite the file if it already exists in the destination folder (since overwrite = TRUE
).
Note that you can also use the write.table()
function to write the CSV file to the new directory, which will create a new file in that directory rather than moving the original file. To do so, you can simply specify the new file path as the file
argument in the write.table()
function:
main.r310 chars10 lines
This code will read in the "data.csv" file from the original directory, and write a new copy of the data frame to the new directory as a CSV file using the write.table()
function. The sep = ","
argument specifies the column separator as a comma, and row.names = FALSE
specifies that row names should not be written to the file.
gistlibby LogSnag