Stephen Diehl Stephen Diehl - 1 year ago 83
Bash Question

Running R Scripts with Plots

I have a small shell script (bash) which runs a R script which produces a plot as output. Everything works fine but immedietly after the plot is rendered R quits. Is there a way to keep the R session alive until the plot window is closed.

The shell script.

R --slave --vanilla < myscript.r

And the R script.

daq = read.table(file('mydata.dat'))
//R Completes this and then exits immediately.

Thanks in advance for any help!

Answer Source

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


daq = read.table(file('mydata.dat'))

message("Press Return To Continue")
invisible(readLines("stdin", n=1))

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


or without the shebang:

Rscript /path/to/myscript.r