Skip to content

Axe terms environment in method for recipe steps - #193

Merged
DavisVaughan merged 8 commits into
masterfrom
axe-recipe-step
May 24, 2021
Merged

DavisVaughan merged 8 commits into
masterfrom
axe-recipe-step

Conversation

@juliasilge

Copy link
Copy Markdown
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

@DavisVaughan DavisVaughan left a comment

Copy link
Copy Markdown
Member

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?

Comment thread R/recipe.R Resolved
Comment thread tests/testthat/test-multnet.R Resolved
@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
Copy Markdown
Member

Thanks!

@github-actions

github-actions Bot commented Jun 8, 2021

Copy link
Copy Markdown
Contributor

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