One strategy is to wrap the code in { }
so that the code is executed as a single block. For example,
{ceiling(quantile(rnorm(20), seq(0, 1, length.out=8))); rnorm(10)}
will run, but
{ceiling(quantile(rnorm(20), seq(0, 8, length.out=8))); rnorm(10)}
will error out and the second command, rnorm(10)
will not run.
d.b. mentions in the comments setting the options(error)
. According to ?options
, by default, this is set to NULL
. If you want the code to stop at an error and enter debugging mode, you could type
options(error=recover)
in an initial session or put this into your .Rprofile and then R will enter a debugging mode upon hitting an error.
For the code above, you would see
{ceiling(quantile(rnorm(20), seq(0, 8, length.out=8))); rnorm(10)}
Error in quantile.default(rnorm(20), seq(0, 8, length.out = 8)) :
'probs' outside [0,1]
Enter a frame number, or 0 to exit
1: #1: quantile(rnorm(20), seq(0, 8, length.out = 8))
2: quantile.default(rnorm(20), seq(0, 8, length.out = 8))