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":
38 chars2 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:
19 chars2 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