Sorry, I meant to use it as unquoted variables in ellipsis.
For example:
tibble::tibble(x = 1, y = 2, z = 3) |>
(function(data, ...) {
dots <- as.character(rlang::enexprs(...))
data[, dots]
})(x, z)
#> # A tibble: 1 × 2
#> x z
#> <dbl> <dbl>
#> 1 1 3
Here, using -
or !
won't work.
I know that verbs like select internally use column indexes instead of names, which allow the use -
but not !
.
tibble::tibble(x = 1, y = 2, z = 3) |>
(function(data, ...) {
dots <- rlang::expr(c(...))
data[, rlang::eval_tidy(dots)]
})(-2)
#> # A tibble: 1 × 2
#> x z
#> <dbl> <dbl>
#> 1 1 3
Created on 2023-11-08 by the reprex package (v2.0.1)
I was wondering how they do to handle these operators from expressions. I assume they parse the expression and process the data differently depending on the operator but I can't find it in the code. I was curious to see how they do it. It seems to happen inside tidyselect:::vars_select_eval()
and probably inside the data_mask
object coded in C.