0

I am trying to export some data from R to .csv. It was working yesterday but today I got this error message:

Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file 'C:/Users/cgarf/Documents/OTL_Model': Permission denied

I recently changed java versions. I'm not sure if that could be causing the issue or if I'm missing something

r2evans
  • 141,215
  • 6
  • 77
  • 149
cgarfield
  • 1
  • 1
  • 1
  • Please check the folder permissions in properties – akrun Aug 28 '20 at 22:16
  • 1
    Permissions are handled by your operating system, not R. So this really isn't an R issue. Likely you cannot write to that folder from any application with your current user account. – MrFlick Aug 28 '20 at 22:17

1 Answers1

1

That error is often because you are trying to write a file to a directory.

file.exists("quux")
# [1] FALSE
dir.create("quux")
file.exists("quux")
# [1] TRUE
dir.exists("quux")
# [1] TRUE
write.table(mtcars, "quux")
# Warning in file(file, ifelse(append, "a", "w")) :
#   cannot open file 'quux': Permission denied
# Error in file(file, ifelse(append, "a", "w")) : 
#   cannot open the connection

BTW, in case it helps you narrow down where the directory is being used (instead of a filename), I just greped R source (base libraries) and found exactly two instances of ifelse(append, "a", "w"):

(Those links are provided "now" as of commit 5b2f6e4.)

r2evans
  • 141,215
  • 6
  • 77
  • 149