简体   繁体   中英

R CMD BATCH or Rscript with stop on error

I don't think R CMD BATCH or Rscript is supposed to stop on an error, but I would like it to (or something like it).

As an example I have this in test.R :

stop("I really mean stop!")
cat("no, I dont want this printed")

After running R CMD BATCH test.R , I get:

> > stop("I really mean stop!") Error: I really mean stop!
> > 
> > cat("no, I dont want this printed") no, I dont want this printed>

The cat command is executed, even though I don't want it to be.

I've discovered a trick to make a file like runTest.R that contains

source('test.R')

And then if I run R CMD BATCH runTest.R things work as I like.

But I'm looking for a way that's not a trick and where I don't have to create an extra file.

If I remove the following from my .Rprofile I do not have the problem:

options(error = utils::dump.frames)

Thanks to the commenters for helping me figure that out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM