Permission Denied when writing file

My computer is giving me permission denied when I try to write csv or text files to my working directory folder. How do I fix it?

write(filled, file ="/Users/hp/Documents/ESS580/ClassProject1/EDSFA_2022/filled_acres.csv", sep = ',')

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 '/Users/hp/Documents/ESS580/ClassProject1/EDSFA_2022/filled_acres.csv': Permission denied

I have tried to fix this on my own using the below post. I have double checked that the permissions on the folder allow for reading and writing, and I use Rstudio as administrator. To my understanding, there isnt antivirus software on this computer.

what shows when you getwd() ?

The working directory my R.proj is in.
"C:/Users/hp/...."

So then i dont think you need the path you are giving to write to begin Users\hp otherwise it's repetition

Either you must write a complete absolute path, which on windows is "c:/Users/hp/Documents/..."
or you must write the path relative to your working directory. So if you want to store the csv-file in your working directory, just write "filled_acres.csv".

When I tried giving it just the name it came back with the same permissions error. I am thinking this is a larger issue.

write(kersey, file ="filled_acres.csv", sep = ',')
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 'filled_acres.csv': Permission denied

Any chance that you have the file (filled_acres.csv) opened in eg. Excel, while you try writing from R? That will lock the file, and give exactly the error you write.

1 Like

No, I am trying to create the file to begin with not edit it.

Hmm - I'm getting low on ideas. Have you tried writing to other files with other methods? What happens if you do:
dput(x=1,file="test.Robj")
or
dput(x=1,file="filled_acres.csv")

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.