[R] Problem of running R console from Java on linux box
ZhaoWei
wzhao1984 at gmail.com
Mon Nov 3 03:19:10 CET 2008
My fault, I used Runtime.getRuntime.exec("/usr/bin/R --vanilla"), and was
prompted with "/usr/bin/R --vanilla not found". This morning I tried command
with String array, it works.
And, you said "vanilla" is a non-interactive mode, so if I have several R
scripts to run, I have to evaluate them one by one: create a R process -> foward
the first script to the process through output stream -> close the output stream
& get feed back from inputstream -> close input stream & exit R -> create a new
process to evaluate the next script.
There is no way to evaluate all commands or scripts in one R process, right?
> ZhaoWei <wzhao1984 at gmail.com> writes:
>
> > Great, "--vanilla" works!
> > Can you please tell me what this parameter means?
> > And, it works with the execuatble(/usr/lib/R/bin/exec/R). I'm wondering
> > is it possible to do the same with the shell script(/usr/bin/R), anyway
> > when you type "R" in command line, it means the shell script.
>
> By 'without /bin/sh' I mean you want to start R as
>
> /usr/bin/R --vanilla
>
> like
>
> String[] cmd = new String[] {"/usr/bin/R", "--vanilla"};
> Process proc = java.lang.Runtime.getRuntime().exec(cmd);
>
> If you do not specify --vanilla, and do
>
> Process proc = java.lang.Runtime.getRuntime().exec("/usr/bin/R");
> // create byte array 'bytes', then
> proc.getErrorStream().read(bytes)
> // interpret bytes as String
>
> you'll see the error
>
> Fatal error: you must specify '--save', '--no-save' or '--vanilla'
>
> You need '--vanilla' because you are creating a non-interactive
> process; --vanilla tells the non-interactive process how to start up
> and shut down
>
> Since the process is not interactive, you can foward bytes to it with
> proc.getOutputStream(), and retrieve results from
> proc.getInputStream() (once the output stream has been closed), but
> you are not interacting with R the way you would at an R prompt.
>
> Martin
>
> > Thanks again!
> >
> >> > Hi the list:
> >> >
> >> > I can not create R process from Java application with my linux box,
> >> > the process never was created, or just terminated immediately after I
> >> > called Runtime.getRuntime().exec(...)
> >> >
> >>
> >> Did you check the error stream? I think you want to start R with a
> >> command line argument like "--vanilla", without /bin/sh.
> >>
> >> Martin
> >>
> >> > The command lines I have tried are(the paths are all correct):
> >> >
> >> > "/bin/sh /usr/bin/R"
> >> > "/bin/sh -c /usr/bin/R"
> >> > "/usr/lib/R/bin/exec/R"(also set R_HOME=/usr/lib/R)
> >> >
> >> > I also tried ProcessBuilder, which is no help. I'm confused, is this
> >> > possible?
> >> >
> >> > Many Thanks!
> >> >
> >> > ______________________________________________
> >> > R-help at r-project.org mailing list
> >> > https://stat.ethz.ch/mailman/listinfo/r-help
> >> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> >> > and provide commented, minimal, self-contained, reproducible code.
> >>
> >> --
> >> Martin Morgan
> >> Computational Biology / Fred Hutchinson Cancer Research Center
> >> 1100 Fairview Ave. N.
> >> PO Box 19024 Seattle, WA 98109
> >>
> >> Location: Arnold Building M2 B169
> >> Phone: (206) 667-2793
>
> --
> Martin Morgan
> Computational Biology / Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N.
> PO Box 19024 Seattle, WA 98109
>
> Location: Arnold Building M2 B169
> Phone: (206) 667-2793
More information about the R-help
mailing list