Rdatatable / data.table

R's data.table package extends data.frame:
http://r-datatable.com
Mozilla Public License 2.0
3.62k stars 986 forks source link

Using ..1 with data.table gives an error #5460

Open ggrothendieck opened 2 years ago

ggrothendieck commented 2 years ago

The following results in an error:

BODdt <- data.table(BOD)
BODdt[, X := sapply(demand, function(...) sqrt(..1))]
## Error in `[.data.table`(BODdt, , `:=`(X, sapply(demand, function(...) sqrt(..1)))) : 
##   Variable '1' is not found in calling scope. Looking in calling scope because this symbol was prefixed with .. in the j= parameter.

Any of these work with no error so it seems it knows not to regard dot dot dot as the variable dot but does not know that it should not regard dot dot 1 as the variable 1.

BODdt <- data.table(BOD)
BODdt[, X := sapply(demand, function(...) sqrt(...))]

SQRT <- function(...) sqrt(..1)
BODdt <- data.table(BOD)
BODdt[, X := sapply(demand, SQRT)]

BODdt <- data.table(BOD)
BODdt[, X := sapply(demand, function(...) sqrt(...elt(1)))]
jangorecki commented 2 years ago

Most likely is a corner case of double dot prefix, that we use for looking up variable from parent frame. We need to add extra handling of that. Thank you for reporting.

MichaelChirico commented 2 years ago

yep... we'll need to match the R symbols regex, and also clarify/document than non-syntactic names are not supported in .. shorthand