doCallWE: Innermost Computation: Error Catching Version of do.call()

View source: R/doCallWE.R

doCallWER Documentation

Innermost Computation: Error Catching Version of do.call()

Description

doCallWE() performs the innermost computation of the simulation study at hand. It is a version of do.call(f, argl, *), with care of catching and storing both error and warnings (via tryCatch.W.E()) and measures user time. This is useful in large(r) simulation studies.

mkTimer() returns a function to be passed as timer to doCallWE().

Usage

doCallWE(f, argl, 
         timer = mkTimer(gcFirst=FALSE))

mkTimer(gcFirst)

Arguments

f

a function which given data and parameters, computes the statistic we are simulating.

argl

list of arguments for f().

timer

a function similar to system.time(); by default, measure user time in milliseconds.

gcFirst

logical, passed to system.time(), as it is called from the resulting function mkTimer().

Details

Note that gcFirst=FALSE is default for a good reason: if a call to doOne() is relatively fast, calling gc() every time is unnecessarily expensive and may completely dominate the overall simulation run time. For serious run time measurement, gcFirst=TRUE is preferable, as it ensures less variable timings, see system.time.

Value

doCallWE() returns a list with components

value

f(\langle \mathtt{argl} \rangle), if there was no error, NULL otherwise.

error

error message (see simpleError or stop()), NULL otherwise.

warning

warning message (see simpleWarning or warning()), NULL otherwise.

time

time, as measured by timer(); defaults to milliseconds without garbage collection.

Author(s)

Marius Hofert and Martin Maechler.

See Also

do.call, tryCatch.W.E.

Examples

set.seed(61)
L <- log(abs(rt(n=100, df = 1.5)))
r <- doCallWE(quantile, list(L, probs= 0.95))
## set timer for  "no timing" :
u <- doCallWE(quantile, list(L, probs= 0.95), timer = function(E) { E; NULL })
stopifnot(is.null(r$error),
	  all.equal(r$value, quantile(L, 0.95)),
	  identical(r[1:3], u[1:3]), is.null(u[["time"]]))

simsalapar documentation built on April 27, 2023, 9:05 a.m.