I have a very simple code that appears to work perfectly in RStudio but does nothing if I source the script from within R:
If I save the following as test.R
library(ggplot2)
png(file = paste(format(Sys.time(), "%Y-%m-%d"
),
"-plot-",
"1",
".png",
sep = ""
)
)
ggplot(data = mtcars) +
geom_point(aes(x = drat, y = wt)
)
dev.off()
I see the png saved in my working directory if source the above script via RStudio. But if I open R from the command line, and source the same script my plot doesn't get saved. Is there a reason for this? (I checked I have the right working directory via getwd()).
Does R from the command line save to some other location? Or is there something else going on?