I am trying to figure out if there is a good way of using glue() in j of a data.table:
library(data.table)
library(glue)
data(iris)
dt.iris <- data.table(iris)
dt.iris[, myText := glue('The species is {Species} with sepal length of {Sepal.Length}')]
# Error in eval(parse(text = text, keep.source = FALSE), envir) :
# object 'Species' not found
I can use it if I indicate .envir = .SD:
dt.iris[, myText := glue('The species is {Species} with sepal length of {Sepal.Length}', .envir = .SD)]
# works OK
but I am wondering if I can find some way without adding this every time. Maybe something like that:
glue1 <- function(...) glue(..., .envir = ???)
You could do
Testing, we have:
Created on 2023-11-11 with reprex v2.0.2