Hello,
I've been struggling with RStudio lateley. Whenever I want to save a plot (even the simplest ones) as a jpg, I get an "R code execution error".
Given that it worked before my PC had to restart for an update, I already tried shutting down and restarting my PC, as well as terminating and restarting R Sessions, I deleted R and installed it again, nothing helped and I don't know why.
I created a simple example with:
x<-c(1,2,3,4)
y<-c(2,4,6,8)
plot(x~y)
And the plot shows without Problems. But when I click "Export"->"Save As Image", without changing anythig I get:
After typing: "png("pplot1.jpeg")"
I get:
"Error in png("pplot1.jpeg") : unable to start png() device
In addition: Warning messages:
1: In png("pplot1.jpeg") : unable to open file 'pplot1.jpeg' for writing
2: In png("pplot1.jpeg") : opening device failed"
Hopefully you have seen my edit and have rebooted the computer. This often cures strange things.
If a reboot does not help we need to try and see if the problem is in RStudio or R.
Shut down RStudio and load R on its own. There should be an Icon on the desktop. Try running
x<-c(1,2,3,4)
y<-c(2,4,6,8)
png("pplot1.jpeg")
plot(x~y)
dev.off()
there. If you get an errer there, I am not sure what to suggest other than a new installation of R. I have not used Windows in at least 10 years so I cannot suggest any easier.
Best of luck
Unable to open file for writing sounds like you don't have permission to write to the directory. What happens if you supply a full path to a location where you know you have write permissions?
I'm not sure where RStudio thinks ~ is on a Windows machine, nor what the directory it is considering the current working directory for writing the file. Trying to rule out file permissions as the culprit by specifying a path that is known writable.
rebooting the Computer didn't work, but typing it in R did (meaning I have a "pplot1.jpeg" file), so the problem must be in RStudio, right? How do I go on?
I really have no idea. I use RStudio all the time but I am not much use at troubleshooting it.
Ah, wait a minute grosscol makes a very good point that I missed
It looks like a permissions problem. I never use the Export function and may have missed the blindingly obvious answer.
When you export check the directory you are writing to. The Directory button is in the upper left corner just below the Image Format. text. If necessary change it to a directory you know you have permission to write to and see what happens.
It seems to me RStudio has no permission to write to at all. I tried different directories, even just "C:/" and the plot that saved from R is saved in a directory that RStudio can't write to. Do you know where I can see and change RStudio's permissions?
Edit: The problem startet happening right after Windows needed an update, so I think this is likely