tidyverts / tidyverts/fabletools

Modeling functions have problems with environments of custom transformations

Open
#311 0 comments 1 reaction 1 assignee View on GitHub

@mitchelloharawild is already working on this.

Since Apr 13, 2021.

Dominant language
R
Stars
98
Forks
37
PR merge metrics
No merged PRs in 30d

Description

When using custom transformation functions (like my_scaled_logit() below), the modeling functions like ETS() or ARIMA() seem to search only the global environment for their definition. When run inside a different environment, an error is thrown, see below.

The problem is best illustrated in the example below, I think. However, I actually ran into this when rendering an RMarkdown document using rmarkdown::render(envir = new.env()).

library("fpp3")

df1 <- dplyr::filter(prices, !is.na(eggs))

f1 <- function(data = NULL) {

    my_scaled_logit <- fabletools::new_transformation(
        transformation = function(x, lower = 10, upper = 400) {
            log((x - lower) / (upper - x))
        },
        inverse = function(x, lower = 10, upper = 400) {
            (upper - lower) * exp(x) / (1 + exp(x)) + lower
        }
    )
    
    data %>%
        model(ETS(my_scaled_logit(eggs)))
}

f1(df1)
#> Error in get("my_scaled_logit"): object 'my_scaled_logit' not found

Created on 2021-02-18 by the reprex package (v1.0.0)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 4.0.3 (2020-10-10)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  German_Germany.1252         
#>  ctype    German_Germany.1252         
#>  tz       Europe/Berlin               
#>  date     2021-02-18                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package        * version date       lib source        
#>  anytime          0.3.9   2020-08-27 [1] CRAN (R 4.0.2)
#>  assertthat       0.2.1   2019-03-21 [1] CRAN (R 4.0.0)
#>  backports        1.2.1   2020-12-09 [1] CRAN (R 4.0.3)
#>  cli              2.3.0   2021-01-31 [1] CRAN (R 4.0.3)
#>  colorspace       2.0-0   2020-11-11 [1] CRAN (R 4.0.3)
#>  crayon           1.4.1   2021-02-08 [1] CRAN (R 4.0.3)
#>  DBI              1.1.1   2021-01-15 [1] CRAN (R 4.0.3)
#>  digest           0.6.27  2020-10-24 [1] CRAN (R 4.0.3)
#>  distributional   0.2.2   2021-02-02 [1] CRAN (R 4.0.3)
#>  dplyr          * 1.0.4   2021-02-02 [1] CRAN (R 4.0.3)
#>  ellipsis         0.3.1   2020-05-15 [1] CRAN (R 4.0.2)
#>  evaluate         0.14    2019-05-28 [1] CRAN (R 4.0.0)
#>  fable          * 0.3.0   2021-02-03 [1] CRAN (R 4.0.3)
#>  fabletools     * 0.3.0   2021-01-19 [1] CRAN (R 4.0.3)
#>  farver           2.0.3   2020-01-16 [1] CRAN (R 4.0.0)
#>  feasts         * 0.1.7   2021-02-05 [1] CRAN (R 4.0.3)
#>  fpp3           * 0.4.0   2021-02-06 [1] CRAN (R 4.0.3)
#>  fs               1.5.0   2020-07-31 [1] CRAN (R 4.0.2)
#>  generics         0.1.0   2020-10-31 [1] CRAN (R 4.0.3)
#>  ggplot2        * 3.3.3   2020-12-30 [1] CRAN (R 4.0.3)
#>  glue             1.4.2   2020-08-27 [1] CRAN (R 4.0.2)
#>  gtable           0.3.0   2019-03-25 [1] CRAN (R 4.0.0)
#>  highr            0.8     2019-03-20 [1] CRAN (R 4.0.0)
#>  htmltools        0.5.1.1 2021-01-22 [1] CRAN (R 4.0.3)
#>  knitr            1.31    2021-01-27 [1] CRAN (R 4.0.3)
#>  lifecycle        0.2.0   2020-03-06 [1] CRAN (R 4.0.0)
#>  lubridate      * 1.7.9.2 2020-11-13 [1] CRAN (R 4.0.3)
#>  magrittr         2.0.1   2020-11-17 [1] CRAN (R 4.0.3)
#>  munsell          0.5.0   2018-06-12 [1] CRAN (R 4.0.0)
#>  pillar           1.4.7   2020-11-20 [1] CRAN (R 4.0.3)
#>  pkgconfig        2.0.3   2019-09-22 [1] CRAN (R 4.0.0)
#>  progressr        0.7.0   2020-12-11 [1] CRAN (R 4.0.3)
#>  ps               1.5.0   2020-12-05 [1] CRAN (R 4.0.3)
#>  purrr            0.3.4   2020-04-17 [1] CRAN (R 4.0.0)
#>  R6               2.5.0   2020-10-28 [1] CRAN (R 4.0.3)
#>  Rcpp             1.0.6   2021-01-15 [1] CRAN (R 4.0.3)
#>  reprex           1.0.0   2021-01-27 [1] CRAN (R 4.0.3)
#>  rlang            0.4.10  2020-12-30 [1] CRAN (R 4.0.3)
#>  rmarkdown        2.6     2020-12-14 [1] CRAN (R 4.0.3)
#>  rstudioapi       0.13    2020-11-12 [1] CRAN (R 4.0.3)
#>  scales           1.1.1   2020-05-11 [1] CRAN (R 4.0.0)
#>  sessioninfo      1.1.1   2018-11-05 [1] CRAN (R 4.0.2)
#>  stringi          1.5.3   2020-09-09 [1] CRAN (R 4.0.2)
#>  stringr          1.4.0   2019-02-10 [1] CRAN (R 4.0.0)
#>  styler           1.3.2   2020-02-23 [1] CRAN (R 4.0.0)
#>  tibble         * 3.0.6   2021-01-29 [1] CRAN (R 4.0.3)
#>  tidyr          * 1.1.2   2020-08-27 [1] CRAN (R 4.0.2)
#>  tidyselect       1.1.0   2020-05-11 [1] CRAN (R 4.0.0)
#>  tsibble        * 0.9.3   2020-10-06 [1] CRAN (R 4.0.3)
#>  tsibbledata    * 0.2.0   2020-06-04 [1] CRAN (R 4.0.3)
#>  vctrs            0.3.6   2020-12-17 [1] CRAN (R 4.0.3)
#>  withr            2.4.1   2021-01-26 [1] CRAN (R 4.0.3)
#>  xfun             0.21    2021-02-10 [1] CRAN (R 4.0.3)
#>  yaml             2.2.1   2020-02-01 [1] CRAN (R 4.0.2)
#> 
#> [1] D:/Users/BKU/HansjoergPlieninger/Documents/R/win-library/4.0
#> [2] D:/Users/BKU/HansjoergPlieninger/Documents/R/R-4.0.3/library

I don't know whether this is related to tidyverts/fable#80, but I'm referencing it here in case it is.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.