call_conditionally: Call a Function Conditionally

View source: R/call.R

call_conditionallyR Documentation

Call a Function Conditionally

Description

whoami 1.3.0 uses things like system("getent passwd $(whoami)", intern = TRUE) which I can not tryCatch, as it gives no error nor warning. So this function returns a fallback if the condition given is not TRUE.

Usage

call_conditionally(f, condition, fallback, ..., harden = FALSE)

Arguments

f

The function passed to do.call.

condition

An expression.

fallback

See Description.

...

arguments passed to do.call.

harden

Set to TRUE to return fallback if do.call fails.

Value

The return value of f or fallback.

See Also

Other call functions: call_safe()

Examples

call_conditionally(get_package_version,
                   condition = TRUE,
                   args = list(x = "fritools"),
                   fallback = "0.0")
call_conditionally(get_package_version,
                   condition = FALSE,
                   args = list(x = "fritools"),
                   fallback = "0.0")
call_conditionally(get_package_version,
                   condition = TRUE,
                   args = list(x = "not_there"),
                   harden = TRUE,
                   fallback = "0.0")

fritools documentation built on Nov. 19, 2023, 1:06 a.m.