Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSE for trending:::fit.list() is broken #22

Open
TimTaylor opened this issue Apr 14, 2023 · 1 comment · May be fixed by #23
Open

NSE for trending:::fit.list() is broken #22

TimTaylor opened this issue Apr 14, 2023 · 1 comment · May be fixed by #23

Comments

@TimTaylor
Copy link
Contributor

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

@TimTaylor
Copy link
Contributor Author

This means fixing reconhub/trendbreaker#56 is not trivial

@TimTaylor TimTaylor linked a pull request Apr 14, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant