Hi, We've encountered a difference in running time between a straight function call and the same call using do.call when the called function generated an error. We've isolated the problem to the following small reproducible example:
Consider the following function: foo <- function(nr = 2e6, nc=3, use.do.call = FALSE) { nn <- paste("V", 1:nc, sep="") z <- data.frame(matrix(rnorm(nr*nc), nrow=nr, ncol = nc, dimnames = list(NULL, nn))) foo2 <- function(x) x[,"V1"] + x[,"V0"] if (use.do.call) do.call(foo2, list(z)) else foo2(z) } foo2, when called, generates an error because it accesses the V0 column which does not exist. When use.do.call==FALSE, foo2 is called directly. When use.do.call==TRUE, foo2 is called with the same arguments but using do.call. Calling foo() takes about 1 second. Calling foo(use.do.call=TRUE)takes about 20 seconds. Does anybody know what could explain the difference in running time? The difference seems to be related to error handling, since try(foo(use.do.call=TRUE)) takes just 1 second. We used the latest R version (2.15.0) for the test. Any insight will be appreciated, Thanks, Alon [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel