[R] Was confused with options(error = expression(NULL)) in example(stop)

Suharto Anggono Suharto Anggono suharto_anggono at yahoo.com
Fri Feb 1 09:40:33 CET 2013


In example for function 'stop' in R, there is
options(error = expression(NULL))
with comment
# don't stop on stop(.)  << Use with CARE! >>

I was interested, wanted to know how "don't stop on stop(.)" was. So, I tried it.

Typing
example(stop)
at the R prompt and pressing ENTER give this.

> example(stop)

stop> options(error = expression(NULL))

stop> # don't stop on stop(.)  << Use with CARE! >>
stop>
stop> iter <- 12

stop> if(iter > 10) stop("too many iterations")
Error in eval(expr, envir, enclos) : too many iterations


R still stops on stop(.).

That confused me. Then, I tried manually. But I still couldn't get
options(error = expression(NULL))
worked. Everything seemed to be as usual. I gave up.

Some time later, I saw somewhere in the internet that
options(error = expression(NULL))
worked in batch mode. Ah, running from R CMD BATCH. It had no effect in interactive session. I hadn't thought of it before.


> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] tools_2.15.2



More information about the R-help mailing list