deprecated_quo_is_present | R Documentation |
lifecycle::is_present
for enquosed deprecated NSE arglifecycle::is_present
is designed for use with args that undergo standard
evaluation, rather than non-standard evaluation (NSE). This function is
designed to fulfill a similar purpose, but for args we have
enquosed in preparation for NSE.
deprecated_quo_is_present(quo)
quo |
enquosed arg |
bool; was quo
"present", or did it look like a missing quosure or
have an expr that looked like deprecated()
or lifecycle::deprecated()
?
fn <- function(x = deprecated()) {
deprecated_quo_is_present(rlang::enquo(x))
}
fn() # FALSE
fn(.data$something) # TRUE
# Functions that wrap `fn` should forward the NSE arg to `fn` using
# [`{{ arg }}`][rlang::embrace-operator] (or, if they are working from an
# argument that has already been defused into a quosure, `!!quo`). (This is
# already how NSE arguments that will be enquosed should be forwarded.)
wrapper1 <- function(x = deprecated()) fn({{ x }})
wrapper2 <- function(x = lifecycle::deprecated()) fn({{ x }})
wrapper3 <- function(x) fn({{ x }})
wrapper4 <- function(x) fn(!!rlang::enquo(x))
wrapper1() # FALSE
wrapper2() # FALSE
wrapper3() # FALSE
wrapper4() # FALSE
# More advanced: wrapper that receives an already-enquosed arg:
inner_wrapper <- function(quo) fn(!!quo)
outer_wrapper1 <- function(x = deprecated()) inner_wrapper(rlang::enquo(x))
outer_wrapper1() # FALSE
# Improper argument forwarding from a wrapper function will cause this
# function to produce incorrect results.
bad_wrapper1 <- function(x) fn(x)
bad_wrapper1() # TRUE, bad
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.