move a directory in r

To move a directory in R, you can use the file.rename() function. This function is capable of renaming files as well as directories.

The syntax for renaming a directory in R is as follows:

main.r
file.rename(from = "old_directory_name", to = "new_directory_name")
68 chars
2 lines

For example, if you want to move a directory called "my_folder" from the current working directory to a new directory called "new_directory", you can use the following code:

main.r
file.rename(from = "my_folder", to = "new_directory/my_folder")
64 chars
2 lines

Here, the from argument specifies the current location and name of the directory to be moved, while to argument specifies the new location and name of the directory.

Note that the file.rename() function also works for files. In case you want to move a file instead of a directory, you can use the same function with appropriate arguments for from and to.

gistlibby LogSnag