[R] Continue R CMD BATCH on error

Andreas Wittmann andreas_wittmann at gmx.de
Mon Apr 13 11:14:49 CEST 2009


Dear R useRs,

after searching r-help and r-manuals for about one hour i have the 
following, probably easy question for you.

i have the following R-code, in the file test01.R

################################################################################

`fun1` <- function(x)
{
  x <- x + 2
 
  if(x == 5)
    stop("failure")

  return(x)
}

`fun2` <- function(x)
{
  x <- x + 4
 
  return(x)
}

x <- 1:10
val1 <- val2 <- numeric(10)

for(i in 1:10)
{
  val1[i] <- fun1(x[i])
}

for(i in 1:10)
{
  val2[i] <- fun2(x[i])
}

################################################################################

then i want to do

R CMD BATCH test01.R

the result file test01.Rout does not contain the computation of val2 and 
it stops in the for loop of val1.
how can i avoid this and continue the computation on error?

best regards

Andreas




More information about the R-help mailing list