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

Axe terms environment in method for recipe steps #193

Merged
merged 8 commits into from
May 24, 2021

Conversation

juliasilge
Copy link
Member

Closes #192

This PR changes the axe_env.step method to nuke the terms environment. I deleted all the methods that did only that, because they can use this method now.

I made all the dplyr-ish steps that had the same thing happening in their axe methods inherit straight from axe_env.step_arrange so we can change once in the future if needed. I also moved these around a bit in the file so these are together. I think these were in alphabetical order before so I can move them back in you prefer that, vs. similar steps together.

Here are results from the current main branch:

## similar to reported issue from OP
library(recipes)
#> Loading required package: dplyr
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
#> 
#> Attaching package: 'recipes'
#> The following object is masked from 'package:stats':
#> 
#>     step
library(butcher)

prepped_rec <- 
  recipe(Species ~ ., data = iris) %>% 
  step_normalize(all_numeric()) %>% 
  step_pca(all_numeric()) %>%
  prep()

prepped_rec <- butcher(prepped_rec)

prepped_plus <- function() {
  some_junk_in_the_environment <- runif(1e6) 
  
  prepped_rec <- 
    recipe(Species ~ ., data = iris) %>% 
    step_normalize(all_numeric()) %>% 
    step_pca(all_numeric()) %>% 
    prep()
  
  prepped_rec <- butcher(prepped_rec)
  prepped_rec
}

lobstr::obj_size(prepped_rec)
#> 32,224 B
lobstr::obj_size(prepped_plus())
#> 8,032,552 B

Created on 2021-05-14 by the reprex package (v2.0.0)

And to compare, here are the results from this PR:

## similar to reported issue from OP
library(recipes)
#> Loading required package: dplyr
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
#> 
#> Attaching package: 'recipes'
#> The following object is masked from 'package:stats':
#> 
#>     step
library(butcher)

prepped_rec <- 
  recipe(Species ~ ., data = iris) %>% 
  step_normalize(all_numeric()) %>% 
  step_pca(all_numeric()) %>%
  prep()

prepped_rec <- butcher(prepped_rec)

prepped_plus <- function() {
  some_junk_in_the_environment <- runif(1e6) 
  
  prepped_rec <- 
    recipe(Species ~ ., data = iris) %>% 
    step_normalize(all_numeric()) %>% 
    step_pca(all_numeric()) %>% 
    prep()
  
  prepped_rec <- butcher(prepped_rec)
  prepped_rec
}

lobstr::obj_size(prepped_rec)
#> 24,632 B
lobstr::obj_size(prepped_plus())
#> 24,632 B

Created on 2021-05-14 by the reprex package (v2.0.0)

@juliasilge juliasilge requested a review from DavisVaughan May 15, 2021 00:14
Copy link
Member

@DavisVaughan DavisVaughan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a NEWS bullet?

@DavisVaughan DavisVaughan merged commit 46d4949 into master May 24, 2021
@DavisVaughan DavisVaughan deleted the axe-recipe-step branch May 24, 2021 15:00
@DavisVaughan
Copy link
Member

Thanks!

@github-actions
Copy link

github-actions bot commented Jun 8, 2021

This pull request 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.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing axe_env.step_normalize
2 participants