do.on: Easier sapply/lapply avoiding explicit function

Description Usage Arguments Value Examples

Description

Simpler to demonstrate:

1
2
3
  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

1
2
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 . which will successively become the individual elements of x

...

other "arguments" for expr

simplify

as per sapply, and defaulting to TRUE.

Value

do.on

as per sapply, a vector or array of the same "length" as x.

FOR

a list of the same length as x

Examples

1
2
3
4
5
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:.))

mvbutils documentation built on May 2, 2019, 8:32 a.m.

Related to do.on in mvbutils...