From com|c|@n@44 @end|ng |rom gm@||@com  Mon Mar 18 04:44:08 2019
From: com|c|@n@44 @end|ng |rom gm@||@com (comic fans)
Date: Mon, 18 Mar 2019 11:44:08 +0800
Subject: [Rd] Exit status of Rscript when setting
 options(error=utils::recover)
In-Reply-To: <c5bef2f7-677b-cbdb-914a-1316a21cfe0c@gmail.com>
References: <CAKzW8ok4mRyb5MwAAkaN==9qcq+NrqNv8vj5YsWU_AhZM_gFMg@mail.gmail.com>
 <c5bef2f7-677b-cbdb-914a-1316a21cfe0c@gmail.com>
Message-ID: <CAKzW8o=RJEZ5oiiM2uyRuonKkvQ-h2jdLNcOHboJF9nzwVxy0A@mail.gmail.com>

Thanks for explanation,  so recover in non-interactive session exit
with 0 is expected behavior .
dump.frames said that it always write to file (workspace , or specified file).
I have a R script run as a auto build stage, so I want to print detail
backtrace to console
 (with source file, line number)  for quickly debug, without saving any dump.
I tried

options(error= quote({utils::recover;q(status=1)}))

it do exit with 1 when script has error, but it only shows a stripped
call trace like

Calls: a ... a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> apply

instead of
...
99: rec.R#5: a(v, depth - 1)
100: rec.R#5: a(v, depth - 1)
101: rec.R#5: a(v, depth - 1)
102: rec.R#5: a(v, depth - 1)
103: rec.R#5: a(v, depth - 1)

How can I resolve this ? Thanks for advise


On Fri, Mar 15, 2019 at 10:10 PM Tomas Kalibera
<tomas.kalibera at gmail.com> wrote:
>
>
> Please refer to the documentation (?stop, ?recover, ?dump.frames). In
> non-interactive use, recover() works as dump.frames(). dump.frames() is
> documented not to quit R, and the examples show how to quit the R
> session with a given status automatically after dump.frames(). So in
> line with the documentation, R continues after the error, it reaches the
> end of the input, and returns 0.
>
> When you run the example with the NULL default error handler (not
> setting the error option), the exit status is 1 as documented in ?stop.
>
> To avoid surprise wrt to the exit status or where execution continues,
> it is best not to set default error handlers in non-interactive use (or
> set them so that they exit the session with a given exit status).
>
> Tomas
>
> On 3/10/19 4:15 AM, comic fans wrote:
> > Hello, I've noticed that Rscript didn't exit with error code if I set
> > options error = utils::recover in .Rprofile . for example
> >
> > Rscript -e "asdf"
> >
> > Error: object 'asdf' not found
> > No suitable frames for recover()
> >
> > echo $?
> > 0
> >
> > if didn't set options in .Rprofile, Rscript exit with error code 1, is
> > this expected behavior ?
> >
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



[Rd] Exit status of Rscript when setting options(error=utils::recover)
comic fans