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

selecting no variables in recipes selections in v0.1.15 #603

Closed
kylegilde opened this issue Nov 12, 2020 · 10 comments
Closed

selecting no variables in recipes selections in v0.1.15 #603

kylegilde opened this issue Nov 12, 2020 · 10 comments
Labels
feature a feature request or enhancement

Comments

@kylegilde
Copy link

No description provided.

@kylegilde
Copy link
Author

Hi,

I was checking out the fully supported tidyselect functionality, and I was wondering if the behavior changed when a logical expression selects no columns.

Before this version, it would error out when prepped, but in 0.1.15, it appears that it now will prep and with no changes occurring in the step if no columns are selected. Is this correct?

Thank you!

@topepo
Copy link
Member

topepo commented Nov 12, 2020

Can you give an example?

@kylegilde
Copy link
Author

kylegilde commented Nov 12, 2020

I think this produced an error in earlier recipes versions, and now it seems to handle the no-selection case pretty well now.

> library(recipes)
> rec <- 
+   recipe(as.formula("~."), data = mtcars) %>%
+   step_dummy(all_nominal()) %>% 
+   prep()
> rec
Data Recipe

Inputs:

      role #variables
 predictor         11

Training data contained 32 data points and no missing data.

Operations:

Dummy variables were *not* created since no columns were selected. [trained]

@topepo
Copy link
Member

topepo commented Nov 12, 2020

So I'm pretty sure that it depends on the step. We have not made a global change so that any step is skipped if nothing is selected.

@DavisVaughan
Copy link
Member

DavisVaughan commented Nov 13, 2020

That step in particular always worked fine with empty selections

New recipes (0.1.15)

library(recipes)
rec <- recipe(mpg ~ ., mtcars)
rec <- step_dummy(rec, starts_with("foobar"))
prep(rec)
#> Data Recipe
#> 
#> Inputs:
#> 
#>       role #variables
#>    outcome          1
#>  predictor         10
#> 
#> Training data contained 32 data points and no missing data.
#> 
#> Operations:
#> 
#> Dummy variables were *not* created since no columns were selected. [trained]

Old recipes (0.1.14)

library(recipes)
rec <- recipe(mpg ~ ., mtcars)
rec <- step_dummy(rec, all_nominal())
prep(rec)
#> Data Recipe
#> 
#> Inputs:
#> 
#>       role #variables
#>    outcome          1
#>  predictor         10
#> 
#> Training data contained 32 data points and no missing data.
#> 
#> Operations:
#> 
#> Dummy variables were *not* created since no columns were selected. [trained]

However, it seems I may have inadvertently changed this behavior with other steps when I did the tidyselect updates. We can revert it back, or keep this new behavior, but we should probably add some tests either way.

New recipes (0.1.15)

library(recipes)
rec <- recipe(mpg ~ ., mtcars)
rec <- step_center(rec, starts_with("foobar"))
prep(rec)
#> Data Recipe
#> 
#> Inputs:
#> 
#>       role #variables
#>    outcome          1
#>  predictor         10
#> 
#> Training data contained 32 data points and no missing data.
#> 
#> Operations:
#> 
#> Centering for <none> [trained]

Old recipes (0.1.14)

library(recipes)
rec <- recipe(mpg ~ ., mtcars)
rec <- step_center(rec, starts_with("foobar"))
prep(rec)
#> Error: No variables or terms were selected.

Created on 2020-11-13 by the reprex package (v0.3.0.9001)

@kylegilde
Copy link
Author

@DavisVaughan , I'm glad to know that it wasn't just my imagination!

I would say that I strongly prefer the new behavior where an error does NOT occur. It makes the recipe more dynamic & reusable on different datasets.

It would helpful if the selections doc makes note of this behavior.

https://github.com/tidymodels/recipes/blob/master/R/selections.R

Also, this line in the doc is out of date:

Additionally, the tidyselect domain specific
#' language is not recognized here, meaning that &, |, !, and -
#' will not work.

@DavisVaughan
Copy link
Member

Also, this line in the doc is out of date:

That is specifically about step_interact(), and should still hold

@juliasilge
Copy link
Member

Bigger picture, related to #531

@juliasilge juliasilge added the feature a feature request or enhancement label Dec 4, 2020
@juliasilge
Copy link
Member

Closed in #813 🎉

@github-actions
Copy link

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.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants