how to delete a file with R? [duplicate]

不羁的心 提交于 2019-12-03 18:45:48

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/14219887/how-to-delete-a-file-with-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!