-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
The NSE for trending:::fit.list() is broken when used programatically (i.e within functions). I think it is something to do with passing the correct environment around for evaluation but it's tricky.
library(trending)
# this works
x = rnorm(100, mean = 0)
y = rpois(n = 100, lambda = exp(1.5 + 0.5*x))
dummy <- data.frame(x = x, y = y)
poisson_model <- glm_model(y ~ x , family = poisson)
# this works
fit(poisson_model, data = dummy)
#> <trending_fit_tbl> 1 x 3
#> result warnings errors
#> <list> <list> <list>
#> 1 <glm> <NULL> <NULL>
# this works
fun1 <- function(xx) fit(poisson_model, data = xx)
fun1(dummy)
#> <trending_fit_tbl> 1 x 3
#> result warnings errors
#> <list> <list> <list>
#> 1 <glm> <NULL> <NULL>
# this works
fit(list(pm = poisson_model), data = dummy)
#> <trending_fit_tbl> 1 x 4
#> model_name result warnings errors
#> <chr> <named list> <named list> <named list>
#> 1 pm <glm> <NULL> <NULL>
# this does not work
fun2 <- function(xx) fit(list(pm = poisson_model), data = xx)
(out <- fun2(dummy))
#> <trending_fit_tbl> 1 x 4
#> model_name result warnings errors
#> <chr> <named list> <named list> <named list>
#> 1 pm <NULL> <NULL> <chr [1]>
out$errors
#> $pm
#> [1] "object 'xx' not found"Created on 2023-04-14 with reprex v2.0.2
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels