Running R Scripts with Plots Running R Scripts with Plots shell shell

Running R Scripts with Plots


If you use the Rscript command (which is better suited for this purpose), you run it like this:

#!/usr/bin/Rscriptdaq = read.table(file('mydata.dat'))X11()pairs(daq)message("Press Return To Continue")invisible(readLines("stdin", n=1))

Make sure to set the execute permission on myscript.r, then run like:

/path/to/myscript.r

or without the shebang:

Rscript /path/to/myscript.r


You could add a loop that checks for the graphical device every n seconds:

while (!is.null(dev.list())) Sys.sleep(1)

This will sleep until you close the plot window.


This is not a perfect solution, but you may call locator() just after the plot command.
Or just save the plot to pdf and then invoke pdf viewer on it using system.