Open l-jaye opened 3 years ago
This is an interaction between rlang and data.table. It can be reproduced with the following:
library(rlang)
library(data.table)
x <- quo({
metrics = c("col.x","col.y")
dt = data.table(x = 1:10, y = "test", col.x = 3, col.y = 4)
melt.dt = melt(dt, measure.vars = metrics, variable.name = "metric")
dt = dcast(melt.dt, ... ~ metric, value.var = "value", fill = NA)
})
eval_tidy(x)
#> Error in check_formula(formula, names(data), valnames) :
#> '...' used in an incorrect context
cc: @lionel-
Hi @wch - what is rlang
doing with ...
? While data.table
does NSE to substitute names into the ...
, R still parses the formula without error. Mainly just curious.
... ~ x
#> ... ~ x
rlang::eval_tidy(rlang::quo(...~x))
#> Error in rlang::eval_tidy(rlang::quo(... ~ x)): '...' used in an incorrect context
Now tracked in r-lib/rlang#1124. Thanks for the reprex @ColeMiller1.
Quosures are implemented as formulas for practical/historical reasons. For this reason tidy eval masks contain a special function bound to ~
. The problem is that you can't pass a ...
argument to a closure in a context where none is bound, even if that ...
argument is never evaluated.
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
This is a limitation of R. 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
primitive functions like ~
can be supplied ...
without this check.
So I don't see a simple way forward here.
Describe the problem in detail
Hello! I am having an issue with recent update to either Shiny or data.table, in the data.table dcast() function. I have filed the issue in Rdatatable/data.table#4913, but just to cross-reference. data.table.dcast works fine outside of Shiny.
Example application or steps to reproduce the problem
System details
Browser Version:
Output of
sessionInfo()
: