Specialised vapply
functions for scalars of each of the six atomic classes
in R:
vlapply(X, FUN, ..., USE.NAMES = TRUE)
viapply(X, FUN, ..., USE.NAMES = TRUE)
vnapply(X, FUN, ..., USE.NAMES = TRUE)
vcapply(X, FUN, ..., USE.NAMES = TRUE)
vzapply(X, FUN, ..., USE.NAMES = TRUE)
vrapply(X, FUN, ..., USE.NAMES = TRUE)
logical (vlapply
)
integer (viapply
)
numeric/real (vnapply
)
character/string (vcapply
)
complex (vzapply
)
raw (vrapply
)
These are simply wrappers around vapply where FUN.VALUE
is pre-filled
with a scalar of the given class.
In addition these can be applied to pull-out fields or methods from R6 or
other OOP objects by supplying the field/method name to FUN
. See examples.
## Specialised vapply
vlapply(logical(10), identity)
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
vzapply(complex(10), identity)
#> [1] 0+0i 0+0i 0+0i 0+0i 0+0i 0+0i 0+0i 0+0i 0+0i 0+0i
## For R6 objects
objs <- list(ooplah$new(), ooplah$new())
# Public field
vcapply(objs, "oop")
#> [1] "oop" "oop"
# Public method
vcapply(objs, "exclaim", "ARGH")
#> [1] "ARGH!" "ARGH!"
vcapply(objs, "hello")
#> [1] "Hello World, Ooplah!" "Hello World, Ooplah!"
vnapply(objs, "generate", 1)
#> [1] 0.6512754 0.5775541
# Active binding
vlapply(objs, "logically")
#> [1] TRUE TRUE