How to Delete a File using R
In this article, we will discuss how to delete a file in R Programming Language.
Directory in use:
Method 1: Using file.remove()
This is the simplest approach to delete a file as in this approach the user just needs to call the file.remove() function which is a bases function of the R programming language and in this function, the user just has to pass the path/name of the file which is to be deleted as the parameter of this function and by this, the user is able to delete the file as per the path/name provided.
file.remove() function is used to delete the file.
- path: A character vector of one or more paths.
Method 2: Using unlink()
In this approach to delete a file, the user just needs to call unlink() function which is a bases function of the R programming language with the path/name of the file which is to be deleted as the parameter of this function and by this, the user is able to delete the file as per the path/name provided.
Unlink() function deletes the file(s) or directories specified by x.
unlink(x, recursive = FALSE, force = FALSE)
- x: a character vector with the names of the file(s) or directories to be deleted.
- recursive: logical. Should directories be deleted recursively?
- force: logical. Should permissions be changed (if possible) to allow the file or directory to be removed?