Cannot export data to a file in R (write.csv)

纵然是瞬间 提交于 2019-12-04 22:51:53
Soid

First part is to check the working directory and ensure that you have write access to that directory. You can check this with getwd(). I can reproduce your error by trying to write to a directory which is read only.

To set the working directory to something else with read access you can type setwd("H:/foo"). Once you have write access the write.csv(x,file='whatever.csv') should work.

I got this error today and fixed it by granting everyone write permission to the folder.

Steps: locate the folder on your PC, right-click and select properties, look for the "Security" tab and edit the permission for all to include "Write"

porkchop

If you don't specify a filename (i.e. C:/temp.csv) and just provide a file path, this same error pops up with both write.csv and write_csv.

I got the same issue today and I know I have full permission to the folder. What worked for me is giving it the absolute path.

write.csv(data, file="C:/project/file.csv")

I just stumbled across this question in trying to figure it out myself. I had the exact same error message pop up a few times:

Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection

After searching around and finding nothing that worked for me I restarted R and received the same message, but also a new error:

In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file 'censoredpath.file.csv': Permission denied

I went to my file explorer and attempted to open the .csv in Excel and it notified me that it was locked by another user (someone else had the file open on their computer). So if it's not a problem with having access to the directory like what's already been suggested, try opening it in Excel to see if that might be the problem.

If you already have a file with the same name in your working directory, you would get that error.

Please check your code about containing any variable name, logical T or F (TRUE or FALSE). If you have you can't shorten logical values as T or F.

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