how to delete a file with R?

RFileFile Manipulation

R Problem Overview


> 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.

R Solutions


Solution 1 - R

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 ...

Solution 2 - R

One of the reasons R cannot be safely exposed to outside users is that it offers complete access to system facilities. In addition to the list.files, list.dirs and the file.remove functions, the system function allows access to pretty much any exploit imaginable.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLaylaView Question on Stackoverflow
Solution 1 - RBen BolkerView Answer on Stackoverflow
Solution 2 - RIRTFMView Answer on Stackoverflow