Search code examples
rpermission-deniedadministratorworking-directorywrite.table

write.table() results in permission denied - common solutions don't work


Can't seem to get permission to write files in R.

Using Windows 10. Only one user account in my computer, have tried running RStudio and Rgui as administrator. getwd() confirms 'C:/Users/name/R' is my working directory. I've gone to properties of the folder and SYSTEM and user have all permissions to write. Have tried changing the directory to no avail.

Using write.table(dataframe, "C:/Users/name/R", sep = "|") and I get the following error:

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/name/R': Permission denied


Solution

  • The path you give to write.table should name a file. You have it naming a directory. R won't replace that directory with a file (thank goodness).

    Try this:

    write.table(dataframe, "C:/Users/name/R/dataframe.txt", sep = "|")