[R] R sometimes dies from within Perl

Martin Maechler maechler at stat.math.ethz.ch
Mon Oct 13 08:41:21 CEST 2003


>>>>> "michael" == michael watson (IAH-C) <michael.watson at bbsrc.ac.uk>
>>>>>     on Fri, 10 Oct 2003 16:11:01 +0100 writes:

    michael> Hi Guys This is a combined Perl/R question,
    michael> hopefully there are enough people out there who use
    michael> both to help me.  I am using the latest versions of
    michael> both on a SUSE Linux 8.2 machine.

    michael> I am wrapping up R in some very simple perl
    michael> scripts.  My problem is that when I run a series of
    michael> commands from within R, with a certain data set,
    michael> one of the commands reports an error but the R
    michael> process remains active.

    michael> However, if I open a pipe within Perl (using
    michael> 'open(R, "| R");') and then pipe the very same
    michael> commands to R using 'print R "<commands>";', then
    michael> when the error occurs, the R process dies and i get
    michael> a message "Execution halted".

    michael> Can anyone think of a reason why R doesn't crash
    michael> normally, but does when controlled from within
    michael> perl?

it doesn't crash, but it stops ("gracefully") because your code
produced an error.

This is the difference between "batch" and interactive mode.
In batch mode, R stops on errors {very reasonably in most
cases!}, in interactive mode it doesn't.

In a shell :
	 echo 'interactive()' | R --slave
gives 
[1] FALSE

You can use try(...) for things that produce errors (but make
sure to deal with  the result of try(.) in error cases), or
since 1.8.0 and inside functions even more generally
tryCatch() and "friends".

Regards,
-- 
Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><




More information about the R-help mailing list