tidyfast icon indicating copy to clipboard operation
tidyfast copied to clipboard

Use of dt_nest in a function

Open qdread opened this issue 8 months ago • 3 comments

Hello, I am having trouble using dt_nest() in a function. Can you please recommend syntax for me?

mtcarsdt <- as.data.table(mtcars)

nestmydatatable <- function(dt, colname) dt_nest(dt, column = get(colname))
nestmydatatable(mtcarsdt, 'cyl')

colname <- 'cyl'

dt_nest(mtcarsdt, column = get(colname))

When dt_nest is called within a function it doesn ot work and returns the error

Error in eval(bysub, x, parent.frame()) : object 'colname' not found

But outside of the function it does work. It has something to do with where eval() is looking for colname but I cannot diagnose the issue. Thanks in advance for your help!

qdread avatar May 08 '25 15:05 qdread