Skip to content

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

Closed

Description

@DavisVaughan

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

Activity

  1. DavisVaughan commented on Nov 18, 2019

    @DavisVaughan
    MemberAuthor

    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)

  2. github-actions commented on Feb 22, 2021

    @github-actions
    Contributor

    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.

  3. locked and limited conversation to collaborators on Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions