how to delete a file with R?

Layla picture Layla · Jan 8, 2013 · Viewed 82.1k times · Source

Possible Duplicate:
Automatically Delete Files/Folders in R

I would like to know if there is a way in R to check up if a file is in my current directory, and if it is there then the program deletes it?

I know that other languages have direct access to OS functions to do this task, but I am a little bit dubious if R has that capability.

Answer

Ben Bolker picture Ben Bolker · Jan 8, 2013

How about:

#Define the file name that will be deleted
fn <- "foo.txt"
#Check its existence
if (file.exists(fn)) {
  #Delete file if it exists
  file.remove(fn)
}

As far as I know, this is a permanent, non-recoverable (i.e. not "move to recycle bin") on all platforms ...