Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test null or missing for enquos-type quosures

Tags:

r

tidyeval

rlang

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
like image 402
Matifou Avatar asked May 07 '19 00:05

Matifou


1 Answers

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

like image 149
G. Grothendieck Avatar answered Nov 20 '22 03:11

G. Grothendieck