| do.on {mvbutils} | R Documentation |
Easier sapply/lapply avoiding explicit function
Description
Simpler to demonstrate:
do.on( find.funs(), environment( get( .))) # same as: lapply( find.funs(), function( x) environment( get( x)))
do.on evaluates expr for all elements of x. The expression should involve the symbol ., and will be cast into a function which has an argument . and knows about any dotdotdot arguments passed to do.on (and objects in the function that calls do.on). If x is atomic (e.g. character or numeric, but not list) and lacks names, it will be given names via named. With do.on, you are calling sapply, so the result is simplified if possible, unless simplify=FALSE (or simplify="array", for which see sapply). With FOR, you are calling lapply, so no simplication is tried; this is often more useful for programming.
Usage
do.on(x, expr, ..., simplify = TRUE)
FOR(x, expr, ...)
Arguments
x |
thing to be iterated over. Names are copied to the result, and are pre-allocated if required as per Description |
expr |
expression, presumably involving the symbol |
... |
other "arguments" for |
simplify |
as per |
Value
do.on |
as per |
FOR |
a list of the same length as |
Examples
do.on( 1:7, sum(1:.))
# 1 2 3 4 5 6 7
# 1 3 6 10 15 21 28
# note the numeric "names" in the first row
FOR( 1:3, sum(1:.))