Search code examples
rrlangtidyeval

How to test null or missing for enquos-type quosures


There's a quite subtle (and very confusing) distinction in rlang that... quosures are not quosure objects! In other terms:

  • quo() and enquo() return a quosure
  • quos() and enquos() return a quosureS, not a quosure (is_quosure(enquos(...)) returns FALSE)

What is the equivalent of quo_is_null() and quo_is_missing() for quosures? In particular, I would like to test the ... argument, captured by enquos(...), is null/missing, how do I do that?

library(rlang)
fo1 <- function(df, var1) {
  dot_vars <- rlang::enquo(var1)
  quo_is_missing(dot_vars)
}

fo2 <- function(df, ...) {
  dot_vars <- rlang::enquos(...)
  quo_is_missing(dot_vars)
}

fo1()
#> [1] TRUE
fo2()
#> `quo` must be a quosure

Solution

  • Use length(dot_vars) to determine if it has a length of 0.