powered by
Build a wrapped function that applies to each unique argument in a vector of arguments once.
VectorizeM( FUN, vectorize.args = arg.names, SIMPLIFY = TRUE, USE.NAMES = TRUE, UNLIST = FALSE )
adapted function (vectorized with one call per different value).
function to apply
a character vector of arguments which should be vectorized. Defaults to first argument of FUN. If set must be length 1.
logical or character string; attempt to reduce the result to a vector, matrix or higher dimensional array; see the simplify argument of sapply.
logical; use names if the first ... argument has names, or if it is a character vector, use that character vector as the names.
logical; if TRUE try to unlist the result.
Only sensible for pure side-effect free deterministic functions.
Vectorize, vapplym, lapplym
Vectorize
vapplym
lapplym
fs <- function(x) { x <- x[[1]]; print(paste("see", x)); sin(x) } fv <- VectorizeM(fs) # should only print "see" twice, not 6 times fv(c(0, 1, 1, 0, 0, 1))
Run the code above in your browser using DataLab