delete a directory in r

To delete a directory in R, you can use the unlink() function. Here's an example of how to delete a directory named "my_folder":

unlink("my_folder", recursive = TRUE)
38 chars
2 lines

The recursive = TRUE argument ensures that all files and subdirectories within "my_folder" are also deleted. Be extremely cautious when using this functionality as it will delete all content within the directory specified.

Alternatively, you can use the rmdir() function to delete an empty directory:

rmdir("my_folder")
19 chars
2 lines

Note that rmdir() only works on empty directories, so you'll need to delete all files and subdirectories within "my_folder" before using rmdir().

gistlibby LogSnag