Skip to content

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

@TimTaylor

Description

@TimTaylor

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions