I have a simple R script in a file Test.r:
x11()
plot(1,1)
From the terminal, I type "Rscript Test.r" and x11 opens and quickly flashes the 开发者_Go百科plot with a point at (1,1), and then quickly closes the window, however x11 remains open.
How do I keep the plot open? Why does it leave so quickly?
R will close the device when the process R dies (as it does when the script completes). The better way to do this is:
pdf("file.pdf")
plot(1,1)
dev.off()
then when you run through the Rscript it will save the file there. Otherwise, you'll have to have R stay alive which isn't really how it should be run in a script.
精彩评论