I’ve a simple R script. When it is run via Rscript.exe, by default it is plotting to a PDF file. I want the script to open a plot window.
I using the command:
Rscript.exe tmp_plot.R
r file tmp_plot.R contains:
x <- 1:10
y <- sin(x)
plot(x,y)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You are running R in a non-interactive way – Rscript is meant for scripts – hence the default plotting device is
pdf(), notx11()or whatever is your OS’s default (windows()by the looks of it). It is trivial to open an alternative device, however; usex11()orwindows(). The problem you have in trying to write a script that will display a plot on screen is that, in your example code shown, the script terminates immediately upon drawing the plot, whether displayed on screen or on thepdf()device. At best you might get it to pause usingSys.sleep(), e.g.:I think you are going about this the wrong way. If you want interactivity when running an R “script”, by which I mean a set of R statements that perform some analysis, you’d be better off getting an editor/IDE on your OS that allows you to step through the script a line or chunk of code at a time, plus interact with the running R session. I use Emacs and the ESS extension for this. You might consider Tinn-R or RStudio as alternatives.
Rscriptis meant for running scripting or batch-like jobs that do not need human interaction or intervention.