Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

call_and_name

Call a function, and give the result names.


Description

Calls a function, and names the result with the first argument.

Usage

call_and_name(fn, x, ...)

Arguments

fn

A function to call. See note below.

x

The first input to fn.

...

Optional additional inputs to fn.

Value

The result of fn(x, ...), with names given by the argument x.

Note

The function, fn, should return an object with the same length as the input x. For speed and simplicity, this isn't checked; it is up to the developer of the assertion to make sure that this condition holds.

See Also

cause and na.

Examples

call_and_name(is.finite, c(1, Inf, NA))

# Make sure that the output is the same size as the input.
# Don't do this:
dont_stop(call_and_name(isTRUE, list(TRUE, FALSE, NA)))
# Do this instead:
call_and_name(
  Vectorize(isTRUE, SIMPLIFY = FALSE),
  list(TRUE, FALSE, NA)
)

assertive.base

A Lightweight Core of the 'assertive' Package

v0.0-9
GPL (>= 3)
Authors
Richard Cotton [aut, cre], Sunkyu Choi [trl], Ivanka Skakun [trl], Gergely Dar<c3><b3>czi [trl], Anton Antonov [trl], Hisham Ben Hamidane [trl], Anja Billing [trl], Aditya Bhagwat [trl], Rasmus B<c3><a5><c3><a5>th [trl], Mine Cetinkaya-Rundel [trl], Aspasia Chatziefthymiou [trl]
Initial release
2021-02-07

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.