delete a file in r

To delete a file in R, you can use the file.remove() function.

Syntax:

main.r
file.remove(file.path)
23 chars
2 lines

where file.path is the path of the file to be removed.

Example: Let's say, we have a file named example.txt in our working directory that we want to delete, then the following code can be used to delete the file:

main.r
file.remove("example.txt")
27 chars
2 lines

Note:

  • If the file is open in any other program, file.remove() will give an error.
  • If the file does not exist in the specified path, file.remove() will give a warning.

gistlibby LogSnag