Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
667 views
in Technique[技术] by (71.8m points)

bash - 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.

#!/bin/bash
R --slave --vanilla < myscript.r

And the R script.

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

Thanks in advance for any help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

#!/usr/bin/Rscript

daq = 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...