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

Should tidy_select_variables() rearrange the order of the variables according to include? #183

Closed
larmarange opened this issue Oct 7, 2022 · 3 comments · Fixed by #184
Closed

Comments

@larmarange
Copy link
Owner

larmarange commented Oct 7, 2022

Currently, the include parameter preserves the original order of the variables.

library(broom.helpers)

mod <- lm(Sepal.Length ~ ., data = iris)

mod |> 
  tidy_plus_plus() |> 
  dplyr::select(term, variable, label, estimate)
#> # A tibble: 6 × 4
#>   term              variable     label        estimate
#>   <chr>             <chr>        <chr>           <dbl>
#> 1 Sepal.Width       Sepal.Width  Sepal.Width     0.496
#> 2 Petal.Length      Petal.Length Petal.Length    0.829
#> 3 Petal.Width       Petal.Width  Petal.Width    -0.315
#> 4 Speciessetosa     Species      setosa          0    
#> 5 Speciesversicolor Species      versicolor     -0.724
#> 6 Speciesvirginica  Species      virginica      -1.02
  

mod |> 
  tidy_plus_plus(include = c(Species, Petal.Length)) |> 
  dplyr::select(term, variable, label, estimate)
#> # A tibble: 4 × 4
#>   term              variable     label        estimate
#>   <chr>             <chr>        <chr>           <dbl>
#> 1 Petal.Length      Petal.Length Petal.Length    0.829
#> 2 Speciessetosa     Species      setosa          0    
#> 3 Speciesversicolor Species      versicolor     -0.724
#> 4 Speciesvirginica  Species      virginica      -1.02

mod |> 
  tidy_plus_plus(include = c(Species, Petal.Length, everything())) |> 
  dplyr::select(term, variable, label, estimate)
#> # A tibble: 6 × 4
#>   term              variable     label        estimate
#>   <chr>             <chr>        <chr>           <dbl>
#> 1 Sepal.Width       Sepal.Width  Sepal.Width     0.496
#> 2 Petal.Length      Petal.Length Petal.Length    0.829
#> 3 Petal.Width       Petal.Width  Petal.Width    -0.315
#> 4 Speciessetosa     Species      setosa          0    
#> 5 Speciesversicolor Species      versicolor     -0.724
#> 6 Speciesvirginica  Species      virginica      -1.02

Created on 2022-10-07 with reprex v2.0.2

To be consistent with dplyr::select(), should the table be reordered according to the include parameters?

@ddsjoberg do you have an advice about it?

@ddsjoberg
Copy link
Collaborator

Oh good point. I think it would be preferable to have the order adjusted with include= if it's not too hairy to make happen.

@larmarange
Copy link
Owner Author

I will explore it

@larmarange
Copy link
Owner Author

It is finally not too complicated to do it. See #184

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

Successfully merging a pull request may close this issue.

2 participants