0

My files are failed to be saved in the correct directory in R. For example, my working directory is /folder/subfolder, but when I save files, they are all saved in /folder. When I use getwd or reset setwd to the subfolder, R shows that I'm in the one I want (/folder/subfolder). Is there anyone knows why?

I'm saving plots and model output on Mac OS:

setwd("/folder/subfolder")

getwd()
"/folder/subfolder"

list.files()
"group.jpg"                   
"Stake.htm"

stargazer(model, out = "sampleOutput")
jpeg("sample.jpg")
plot(sample, horiz = F)
dev.off()

list.file()
"group.jpg"                   
"Stake.htm"

Thanks!

Lumos
  • 1,303
  • 2
  • 17
  • 32

1 Answers1

0

Can you try jpeg("/subfolder/sample.jpg")? That should force R to save to the subfolder.

Isabella Ghement
  • 715
  • 6
  • 14
  • I have tried that, but there is an error `No such file or directoryError in file(file, ifelse(append, "a", "w")) : cannot open the connection`. – Lumos Mar 17 '18 at 23:40
  • Can you try the things recommended in Maurice Reeves' answer here: https://stackoverflow.com/questions/17156445/why-i-get-this-error-writing-data-to-a-file ? It's possible that you need to run R as an administrator to get that command to work (?). – Isabella Ghement Mar 18 '18 at 22:23