strict_sapply: Strict version of 'sapply()'

View source: R/shim-apply.R

strict_sapplyR Documentation

Strict version of sapply()

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

strict_sapply(...)

Arguments

...

Ignored

Examples

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 July 5, 2025, 6:46 a.m.