Learn R Programming

simsalapar (version 1.0-12)

doCallWE: 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)

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.

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().

Author

Marius Hofert and Martin Maechler.

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.

See Also

do.call, tryCatch.W.E.

Examples

Run this code
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"]]))

Run the code above in your browser using DataLab