strict_sapply: Strict version of 'sapply()'

Description Usage Arguments Examples

View source: R/shim-apply.R

Description

'sapply()' is dangerous for programmatic usage because it is type-unstable: you can't predict in advance what it's going to return just be reading the code. Instead use [vapply()], which has an additional argument 'FUN.VALUE', that

Usage

1

Arguments

...

Ignored

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
df <- data.frame(
 a = 1,
 b = "a",
 c = Sys.time(),
 d = ordered("a"),
 stringsAsFactors = FALSE
)

# A list
base::sapply(df, class)
# A matrix
base::sapply(df[3:4], class)
# A vector
base::sapply(df[1:2], class)

hadley/strict documentation built on May 27, 2019, 7:26 a.m.