Skip to content

non-interactive R_tryEval does not return

8 messages · Thomas Friedrichsmeier, Brian Ripley, Martin Morgan

#
...at least I think that is what happens, at least on some
configurations. Here's a repeatable example:

cd R_HOME/tests/Embedding
touch tmp.R
make tryEval

and then (correct)
Error in sqrt("") : Non-numeric argument to mathematical function
Caught an error calling sqrt(). Try again with a different argument.
[1] 3

versus (non-interactive; no return)
Error in sqrt("") : Non-numeric argument to mathematical function
Execution halted
R version 2.5.0 Under development (unstable) (2007-02-21 r40774) 
x86_64-unknown-linux-gnu 

locale:
LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=en_US;LC_COLLATE=en_US;LC_MONETARY=en_US;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C

attached base packages:
[1] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"  
[7] "base"
#
On Wednesday 21 February 2007 23:09, Martin Morgan wrote:
To force interactive use (when embedding), you can set R_Interactive (from 
Rinterface.h) to TRUE, after Rf_initEmbeddedR().

Regards
Thomas Friedrichsmeier
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-devel/attachments/20070221/bc539942/attachment.bin
#
Yes, I know this, but R then acts as though it were interactive!
Thanks for the suggestion though. Martin

Thomas Friedrichsmeier <thomas.friedrichsmeier at ruhr-uni-bochum.de> writes:

  
    
#
Yes, this is as expected/documented (in so far as R_tryEval is 
documented: it is not part of the API, as far as I am aware).

Its point is to be the equivalent of submitting an expression from the 
toplevel and returning to the toplevel, without using R_ReadConsole. So it 
behaves in just the same ways as any other R session with respect to 
R errors.

I think in all the intended uses R would be in interactive mode, and I 
suspect it is an oversight that Rf_initEmbeddedR does not set that on 
Unix-alikes (it does on Windows).  You can set R_Interactive afterwards, 
of course.
On Wed, 21 Feb 2007, Martin Morgan wrote:

            

  
    
#
On Wednesday 21 February 2007 23:53, Martin Morgan wrote:
If that is a problem, another way around it would be to set options("error") 
instead.

Regards
Thomas Friedrichsmeier
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-devel/attachments/20070222/03a806ea/attachment.bin
#
On Wednesday 21 February 2007 23:58, Prof Brian Ripley wrote:
Fortunately, it is part of the API.

Regards
Thomas Friedrichsmeier
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-devel/attachments/20070222/c34201f4/attachment.bin
#
Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
Unpacking the above a bit, I guess the meaning of 'as expected /
documented' is that in non-interactive modes errors halt R (in
errors.c just before LONGJMP(R_ToplevelContext->cjmpbuf, 0)). This
does not seem quite consistent with the idea that R_tryEval is 'the
equivalent of submitting an expression from the toplevel and returning
to the toplevel', since in this case there is no return to the top
level.  This tension is where my problem came from.
Alternative GUIs might want an interactive, embedded R. I would have
thought other uses (web services for me) would rather a
non-interactive embedded R. Whatever the case, I likely over-worried
the consequences of R_Interactive=TRUE; it seems only to matter with
plots, or when there is a segfault (plus whatever user packages might
choose to do differently in response to interactive()).

Thanks to both for the help,

Martin

  
    
#
On Thu, 22 Feb 2007, Thomas Friedrichsmeier wrote:

            
I was unaware that you were the arbiter of what is part of the API.
R_tryEval is not mentioned in 'Writing R Extensions', which is.