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

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 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")