r-lib / rlang

Low-level API for programming with R
https://rlang.r-lib.org
Other
511 stars 138 forks source link

`eval_tidy()` with `...` in two-sided formula #1124

Open lionel- opened 3 years ago

lionel- commented 3 years ago
rlang::eval_tidy(... ~ 1)
#> Error in rlang::eval_tidy(... ~ 1) : '...' used in an incorrect context

rlang::eval_tidy(1 ~ ...)
Error in rlang::eval_tidy(1 ~ ...) : '...' used in an incorrect context

Causes trouble with data.table: https://github.com/rstudio/shiny/issues/3303 and https://github.com/Rdatatable/data.table/issues/4913

lionel- commented 3 years ago

This is a limitation of R.

tilde <- function(x, y) list(substitute(x), substitute(y))
tilde(1, ...)
#> Error: '...' used in an incorrect context

ignore <- function(x, y) NULL
ignore(1, ...)
#> Error: '...' used in an incorrect context

The argument application routine of the interpreter checks that the calling environment has dots: https://github.com/wch/r-source/blob/2ab3b85b/src/main/eval.c#L3203-L3204 Only SPECIALSXP functions like ~ can be supplied ... without this check.

lionel- commented 3 years ago

One way forward is #1145.

stewerner commented 2 months ago

I just stumbled across this in a {shiny} / {data.table} context. Thanks for providing the workaround.