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

`juice()` should always return the same number of rows as the template #411

Closed
DavisVaughan opened this issue Nov 18, 2019 · 1 comment
Closed

Comments

@DavisVaughan
Copy link
Contributor

@DavisVaughan DavisVaughan commented Nov 18, 2019

In the case of juice() where no terms are selected, a tibble with the same number of rows as the template should be returned rather than a completely empty tibble with 0 rows and 0 columns.

library(recipes)

rec <- recipe(~ ., data = iris) %>% 
  step_log(Sepal.Width)

prepped_rec <- prep(rec, iris)

juice(prepped_rec, all_predictors())
#> # A tibble: 150 x 5
#>    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#>           <dbl>       <dbl>        <dbl>       <dbl> <fct>  
#>  1          5.1        1.25          1.4         0.2 setosa 
#>  2          4.9        1.10          1.4         0.2 setosa 
#>  3          4.7        1.16          1.3         0.2 setosa 
#>  4          4.6        1.13          1.5         0.2 setosa 
#>  5          5          1.28          1.4         0.2 setosa 
#>  6          5.4        1.36          1.7         0.4 setosa 
#>  7          4.6        1.22          1.4         0.3 setosa 
#>  8          5          1.22          1.5         0.2 setosa 
#>  9          4.4        1.06          1.4         0.2 setosa 
#> 10          4.9        1.13          1.5         0.1 setosa 
#> # … with 140 more rows

juice(prepped_rec, all_outcomes())
#> # A tibble: 0 x 0

Created on 2019-11-18 by the reprex package (v0.3.0.9000)

This would help with tidymodels/hardhat#95 and be more consistent

@DavisVaughan
Copy link
Contributor Author

@DavisVaughan DavisVaughan commented Nov 18, 2019

This also makes it more consistent with dplyr

suppressPackageStartupMessages(library(recipes))

rec <- recipe(~ Sepal.Width, iris) %>%
  prep(iris)

# should be 150 rows
juice(rec, all_outcomes())
#> # A tibble: 0 x 0

dplyr::select(iris, dplyr::matches("x"))
#> data frame with 0 columns and 150 rows

Created on 2019-11-18 by the reprex package (v0.3.0.9000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant
You can’t perform that action at this time.