[Rd] stop R mainloop without calling exit(1)
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Aug 31 15:22:21 CEST 2006
This is already covered in the R-devel version of R: please consult
`Writing R Extensions' in that version.
On Thu, 31 Aug 2006, Thomas Kelder wrote:
> Hello,
>
> I'm trying to make my Java application work with R, which involves
> sending and retrieving data and to run R functions from within the
> Java application. I also need to have "live interaction" with R, to
> show the R console output (e.g. warnings and print) and to enable the
> user to enter input when a function asks for it.
>
> Therefore I created a simple R console in Java using JRI
> (http://rosuda.org/JRI/), and it works ok. The only problem is that I
> have to start the R main loop which doesn't return.
But that's not true. The documented way is
setup_Rmainloop
run a loop (which can return)
end_Rmainloop
The problem was that the only documented way to shut R down cleanly was
end_Rmainloop (which did call exit), whereas there now is Rf_endEmbeddedR.
> The only way to stop it is to give R the quit command ('q()'), but then
> 'exit(1)' is called from the R code and the Java Virtual Machine
> (including my application) also shuts down.
That's because you called end_Rmainloop, possibly by calling
run_Rmainloop rather than taking control of the loop.
It seems that almost all users of embedded R did not call end_Rmainloop,
and I met this when creating a common embedding interface for Unix and
Windows versions of R: the Windows widgets (such as the graphics device)
do need to be told to shut down.
[...]
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel
mailing list