Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove the file when "permisson denied" in R?

Tags:

file

r

My system is "win7", and I want to delete the file "workspace".

file.remove("c:\\workspace")
# [1] FALSE
# Warning message:
# In file.remove("c:\\workspace") :
# cannot remove file 'c:\workspace', reason 'Permission denied'

How can I give the R the power to delete it?

file.info("c:\\workspace")
#               size isdir mode               mtime               ctime
# c:\\workspace    0  TRUE  777 2014-01-01 14:42:51 2014-01-01 14:33:27
#                             atime exe
# c:\\workspace 2014-02-25 09:39:08  no
like image 359
showkey Avatar asked Mar 02 '14 02:03

showkey


1 Answers

@TypeIA answered it in a comment, but I'll formalize it here: help(unlink).

file.create('somefile')
# [1] TRUE
file.remove('somefile')
# [1] TRUE

dir.create('somedir')
file.remove('somedir')
# [1] FALSE
# Warning message:
# In file.remove("somedir") :
#   cannot remove file 'somedir', reason 'Permission denied'
unlink('somedir', recursive=TRUE)

(The directory is gone.)

like image 117
r2evans Avatar answered Sep 22 '22 17:09

r2evans