tidymodels / parsnip

A tidy unified interface to models
https://parsnip.tidymodels.org
Other
587 stars 88 forks source link

Regression Example: Error in current_env() : could not find function "current_env" #36

Closed alexhallam closed 6 years ago

alexhallam commented 6 years ago

I was going through the Regression Example. Below is my code.

#devtools::install_github("topepo/modelgenerics")
#devtools::install_github("topepo/parsnip", dependencies=TRUE)
#install.packages("AmesHousing")
#install.packages("rsample")
#devtools::install_github("imbs-hl/ranger")
#install.packages("rlang")

library(parsnip)
library(AmesHousing)
library(tidyverse)
library(rsample)
library(ranger)

ames <- make_ames()
set.seed(4595)
data_split <- initial_split(ames, strata = "Sale_Price", p = 0.75)

ames_train <- training(data_split)
ames_test  <- testing(data_split)

rf_defaults <- rand_forest(mode = "regression")
rf_defaults

preds <- c("Longitude", "Latitude", "Lot_Area", "Neighborhood", "Year_Sold")

rf_xy_fit <- rf_defaults %>%
  fit(
    x = ames_train[, preds],
    y = log10(ames_train$Sale_Price),
    engine = "ranger"
  )

I get the following error

Error in current_env() : could not find function "current_env"

I thought this was an rlang issue to I removed and reinstalled rlang. Then I thought is was a session issue so I restarted R, still no luck. I was wondering if you had any insight into this error.

alexhallam commented 6 years ago

If it is useful, this is the traceback.

Error in current_env() : could not find function "current_env"
14. eval_tidy(e, ...)
13. eval_mod(fit_call, capture = control$verbosity == 0, catch = control$catch, env = current_env(), ...)
12. form_form(object = object, formula = data_obj$formula, data = data_obj$data, control = control, ...)
11. xy_form(object = object, x = x, y = y, control = control, ...)
10. fit.model_spec(., x = ames_train[, preds], y = log10(ames_train$Sale_Price), engine = "ranger")
9. fit(., x = ames_train[, preds], y = log10(ames_train$Sale_Price), engine = "ranger")
8. function_list[[k]](value)
7. withVisible(function_list[[k]](value))
6. freduce(value, `_function_list`)
5. `_fseq`(`_lhs`)
4. eval(quote(`_fseq`(`_lhs`)), env, env)
3. eval(quote(`_fseq`(`_lhs`)), env, env)
2. withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
1. rf_defaults %>% fit(x = ames_train[, preds], y = log10(ames_train$Sale_Price), engine = "ranger")
topepo commented 6 years ago

The namespace file has import(rlang) so ¯_(ツ)_/¯

Can you install sessioninfo and run session_info() after the error?

alexhallam commented 6 years ago
> session_info()

─ Session info ──────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.4.4 (2018-03-15)
 os       Windows >= 8 x64            
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_United States.1252  
 tz       America/New_York            
 date     2018-08-02                  

─ Packages ───────────────────────────────────────────────────────────────
 package       * version    date       source                               
 AmesHousing   * 0.0.3      2017-12-17 CRAN (R 3.4.4)                       
 assertthat      0.2.0      2017-04-11 CRAN (R 3.4.1)                       
 backports       1.1.2      2017-12-13 CRAN (R 3.4.3)                       
 bindr           0.1.1      2018-03-13 CRAN (R 3.4.4)                       
 bindrcpp      * 0.2.2      2018-03-29 CRAN (R 3.4.4)                       
 broom         * 0.5.0      2018-07-17 CRAN (R 3.4.4)                       
 cellranger      1.1.0      2016-07-27 CRAN (R 3.4.3)                       
 class           7.3-14     2015-08-30 CRAN (R 3.4.4)                       
 cli             1.0.0      2017-11-05 CRAN (R 3.4.3)                       
 clisymbols      1.2.0      2017-05-21 CRAN (R 3.4.4)                       
 colorspace      1.3-2      2016-12-14 CRAN (R 3.4.1)                       
 crayon          1.3.4      2017-09-16 CRAN (R 3.4.3)                       
 CVST            0.2-1      2013-12-10 CRAN (R 3.4.2)                       
 DBI           * 1.0.0      2018-05-02 CRAN (R 3.4.4)                       
 ddalpha         1.3.1.1    2018-02-02 CRAN (R 3.4.4)                       
 DEoptimR        1.0-8      2016-11-19 CRAN (R 3.4.1)                       
 dimRed          0.1.0      2017-05-04 CRAN (R 3.4.2)                       
 dplyr         * 0.7.6      2018-06-29 CRAN (R 3.4.4)                       
 DRR             0.0.3      2018-01-06 CRAN (R 3.4.4)                       
 exasol        * 5.3.0      2018-02-02 Github (EXASOL/r-exasol@382fe86)     
 forcats       * 0.3.0      2018-02-19 CRAN (R 3.4.4)                       
 ggplot2       * 3.0.0.9000 2018-07-25 Github (tidyverse/ggplot2@510b4b4)   
 glue            1.3.0      2018-07-25 Github (tidyverse/glue@66de125)      
 gower           0.1.2      2017-02-23 CRAN (R 3.4.2)                       
 gtable          0.2.0      2016-02-26 CRAN (R 3.4.1)                       
 haven           1.1.2      2018-06-27 CRAN (R 3.4.4)                       
 hms             0.4.2      2018-03-10 CRAN (R 3.4.4)                       
 httr            1.3.1      2017-08-20 CRAN (R 3.4.4)                       
 ipred           0.9-6      2017-03-01 CRAN (R 3.4.2)                       
 jsonlite        1.5        2017-06-01 CRAN (R 3.4.4)                       
 kernlab         0.9-25     2016-10-03 CRAN (R 3.4.1)                       
 knitr           1.20       2018-02-20 CRAN (R 3.4.4)                       
 lattice         0.20-35    2017-03-25 CRAN (R 3.4.4)                       
 lava            1.6        2018-01-13 CRAN (R 3.4.4)                       
 lazyeval        0.2.1      2017-10-29 CRAN (R 3.4.3)                       
 lubridate       1.7.4      2018-04-11 CRAN (R 3.4.4)                       
 magrittr        1.5        2014-11-22 CRAN (R 3.4.1)                       
 MASS            7.3-49     2018-02-23 CRAN (R 3.4.4)                       
 Matrix          1.2-12     2017-11-30 CRAN (R 3.4.4)                       
 modelgenerics   0.0.1.9000 2018-08-02 Github (topepo/modelgenerics@ba974e0)
 modelr          0.1.2      2018-05-11 CRAN (R 3.4.4)                       
 munsell         0.4.3      2016-02-13 CRAN (R 3.4.1)                       
 nlme            3.1-131.1  2018-02-16 CRAN (R 3.4.4)                       
 nnet            7.3-12     2016-02-02 CRAN (R 3.4.4)                       
 parsnip       * 0.0.0.9001 2018-08-02 Github (topepo/parsnip@baa0882)      
 pillar          1.3.0      2018-07-14 CRAN (R 3.4.4)                       
 pkgconfig       2.0.1      2017-03-21 CRAN (R 3.4.1)                       
 plyr            1.8.4      2016-06-08 CRAN (R 3.4.1)                       
 prodlim         1.6.1      2017-03-06 CRAN (R 3.4.2)                       
 purrr         * 0.2.5      2018-05-29 CRAN (R 3.4.4)                       
 R6              2.2.2      2017-06-17 CRAN (R 3.4.1)                       
 ranger        * 0.10.3     2018-08-02 Github (imbs-hl/ranger@faedc87)      
 Rcpp            0.12.18    2018-07-23 CRAN (R 3.4.4)                       
 RcppRoll        0.3.0      2018-06-27 Github (kevinushey/RcppRoll@9e5529f) 
 readr         * 1.1.1      2017-05-16 CRAN (R 3.4.1)                       
 readxl          1.1.0      2018-04-20 CRAN (R 3.4.4)                       
 recipes         0.1.2      2018-01-11 CRAN (R 3.4.4)                       
 rlang           0.2.1      2018-05-30 CRAN (R 3.4.4)                       
 robustbase      0.92-8     2017-11-01 CRAN (R 3.4.4)                       
 RODBC           1.3-15     2017-04-13 CRAN (R 3.4.1)                       
 rpart           4.1-13     2018-02-23 CRAN (R 3.4.4)                       
 rsample       * 0.0.2      2017-11-12 CRAN (R 3.4.4)                       
 rstudioapi      0.7        2017-09-07 CRAN (R 3.4.3)                       
 rvest           0.3.2      2016-06-17 CRAN (R 3.4.1)                       
 scales          0.5.0      2017-08-24 CRAN (R 3.4.2)                       
 sessioninfo   * 1.0.0      2017-06-21 CRAN (R 3.4.4)                       
 sfsmisc         1.1-2      2018-03-05 CRAN (R 3.4.4)                       
 stringi         1.1.7      2018-03-12 CRAN (R 3.4.4)                       
 stringr       * 1.3.1      2018-05-10 CRAN (R 3.4.4)                       
 survival        2.41-3     2017-04-04 CRAN (R 3.4.4)                       
 tibble        * 1.4.2      2018-01-22 CRAN (R 3.4.4)                       
 tidyr         * 0.8.1      2018-05-18 CRAN (R 3.4.4)                       
 tidyselect      0.2.4      2018-02-26 CRAN (R 3.4.4)                       
 tidyverse     * 1.2.1      2017-11-14 CRAN (R 3.4.4)                       
 timeDate        3043.102   2018-02-21 CRAN (R 3.4.3)                       
 withr           2.1.2      2018-03-15 CRAN (R 3.4.4)                       
 xml2            1.2.0      2018-01-24 CRAN (R 3.4.4)                       
 yaml            2.1.19     2018-05-01 CRAN (R 3.4.4)                       
topepo commented 6 years ago

It looks like you have to install the devel version of `rlang. That's odd since the DESCRIPTION file has

Remotes:
    tidyverse/rlang

using install_github should update things.

alexhallam commented 6 years ago

That fixed the problem! rlang must be installed via install_github

alexpghayes commented 6 years ago

Just ran into this despite an apparent rlang github install:

> remotes::install_github("topepo/parsnip")
Downloading GitHub repo topepo/parsnip@master
Downloading GitHub repo tidyverse/rlang@master
topepo commented 6 years ago

I downgraded rlang and ran devtools::install_github("topepo/parsnip"). I got me the right version of rlang. Between the remotes reference and and the dependency rlang (>= 0.2.0.9001) in DESCRIPTION, I ]m not sure what else to do.

github-actions[bot] commented 3 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.