fsapply: Fast and loose application of function over list.

Description Usage Arguments Details Value Warning Author(s) Examples

View source: R/fsapply.R

Description

Faster highly stripped down version of sapply()

Usage

1
fsapply(x, FUN)

Arguments

x

a vector (atomic or list) or an expression object.

FUN

the function to be applied to each element of x. In the case of functions like +, the function name must be backquoted or quoted.

Details

This is just a wrapper for unlist(lapply(x, FUN)), which will behave as sapply if FUN returns an atomic vector of length 1 each time.

Speed up over sapply is not dramatic, but can be useful in time critical code.

Value

A vector of results of applying FUN to x.

Warning

Very loose version of sapply which should really only by used if you're confident about how FUN is applied to each entry in x.

Author(s)

Robin Evans

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
x = list(1:1000)
tmp = fsapply(x, sin)

## Not run: 
x = list()
set.seed(142313)
for (i in 1:1000) x[[i]] = rnorm(100)

system.time(for (i in 1:100) sapply(x, function(x) last(x)))
system.time(for (i in 1:100) fsapply(x, function(x) last(x)))

## End(Not run)

rje42/rje documentation built on Aug. 15, 2017, 7:43 a.m.

Related to fsapply in rje42/rje...