Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete a file with R? [duplicate]

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.

like image 831
Layla Avatar asked Jan 08 '13 16:01

Layla


People also ask

How do I delete a file in R?

Method 1: Using file.remove() 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.

How do I eliminate duplicate columns in R?

So, how do you remove duplicate column names in R? The easiest way to remove repeated column names from a data frame is by using the duplicated() function. This function (together with the colnames() function) indicates for each column name if it appears more than once.

How do I duplicate a file in R?

To copy a file in R, use the file. copy() method. The file. copy() function works in the same way as a file.


2 Answers

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

like image 85
Ben Bolker Avatar answered Sep 30 '22 00:09

Ben Bolker


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.

like image 44
IRTFM Avatar answered Sep 29 '22 23:09

IRTFM