Got error when using data.table in qmd code
iMissile opened this issue · comments
iMissile commented
I'm trying to make snapshot from command line with cmd webshot2::rmdshot("test.qmd", file = "tst.png")
an got error
Error in :=`(value, gear + carb) : Check that is.data.table(DT) == TRUE.
Otherwise, := and :=(...) are defined for use in j, once only and in particular ways.
See help(":=")
Rendering the same file in RStudio or through rmarkdown::render
I've got correct .html file.
I suppose that it's caused by absense of data.table
@ Import section in DESCRIPTION.
Finding reasons here:
- https://cran.r-project.org/web/packages/data.table/vignettes/datatable-importing.html
- https://stackoverflow.com/questions/27980835/r-data-table-works-in-direct-call-but-same-function-in-a-package-fails
- https://stackoverflow.com/questions/10527072/using-data-table-package-inside-my-own-package/10529888#10529888
Sample qmd sile:
library(data.table)
library(kableExtra)
library(webshot2)
data <- mtcars
df <- setDT(data)[, value := gear + carb][, .(mpg, value)]
kable(df)