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

using dplyr::tbl_vars(data) instead of names(data) #668

Merged
merged 5 commits into from Aug 8, 2019

Conversation

@romainfrancois
Copy link
Member

commented Jul 1, 2019

library(dplyr, warn.conflicts = FALSE)
library(tidyr)

mini_iris <-
  iris %>%
  group_by(Species) %>%
  slice(1)
mini_iris
#> # A tibble: 3 x 5
#> # Groups:   Species [3]
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species   
#>          <dbl>       <dbl>        <dbl>       <dbl> <fct>     
#> 1          5.1         3.5          1.4         0.2 setosa    
#> 2          7           3.2          4.7         1.4 versicolor
#> 3          6.3         3.3          6           2.5 virginica
mini_iris %>% gather(key = "flower_att", value = "measurement", -group_cols())
#> # A tibble: 12 x 3
#> # Groups:   Species [3]
#>    Species    flower_att   measurement
#>    <fct>      <chr>              <dbl>
#>  1 setosa     Sepal.Length         5.1
#>  2 versicolor Sepal.Length         7  
#>  3 virginica  Sepal.Length         6.3
#>  4 setosa     Sepal.Width          3.5
#>  5 versicolor Sepal.Width          3.2
#>  6 virginica  Sepal.Width          3.3
#>  7 setosa     Petal.Length         1.4
#>  8 versicolor Petal.Length         4.7
#>  9 virginica  Petal.Length         6  
#> 10 setosa     Petal.Width          0.2
#> 11 versicolor Petal.Width          1.4
#> 12 virginica  Petal.Width          2.5

So that tidy selections can use group_cols() (if dplyr 0.8.2 is available) tidyverse/dplyr#4399.

@romainfrancois

This comment was marked as resolved.

Copy link
Member Author

commented Jul 1, 2019

Should this specifically import dplyr >=: 0.8.2 then ?

@hadley

This comment has been minimized.

Copy link
Member

commented Jul 1, 2019

Yeah, can you please bump the dplyr version dependency.

It would also be helpful to add something like:

names <- function(...) abort("Use tbl_vars() instead!")
colnames <- function(...) abort("Use tbl_vars() instead!")

just so we don't reaccidentally introduce this.

OTOH this would tighten the binding between tidyr and dplyr, when we've generally been trying to loosen it. However, that should resolve itself when we update tidyselect to take the data frame as the first argument (so we can do type based selections), so I think this approach is good for now.

romainfrancois and others added some commits Jul 1, 2019

@hadley hadley added this to the v1.0.0 milestone Jul 24, 2019

@hadley hadley merged commit e1d74dc into tidyverse:master Aug 8, 2019

0 of 2 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.