How to remove a directory in R?
In this article, we will discuss how to remove a directory using R programming language.
To remove a directory in R we use unlink(). This function deletes the named directory.
Syntax: unlink(directory-name, recursive = BOOLEAN)
Parameter:
- directory-name: a character vector with the names of the directories to be deleted.
- recursive: BOOLEAN TRUE/FALSE, if true directory is deleted recursively otherwise only empty directories are deleted.
Return: It returns normally 0 for success, 1 for failure. Not deleting a non-existent file is not a failure so in that case return 0.
Note: File naming conventions depend on the platform.
Directory in use:
Directory used
Example: Removing directory using R programming language
R
# list files or directories in working directory list.files (path= "." , pattern= NULL , all.files= FALSE , full.names= FALSE ) # delete the directory demo in working directory unlink ( "Demo" ,recursive= TRUE ) # list files or directories in working directory # after deletion list.files (path= "." , pattern= NULL , all.files= FALSE , full.names= FALSE ) |
Output:
Console Output
Final Directory after running the above code:
Final state of Directory
Please Login to comment...