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

Cannot use purrr-style lambda function with select() (dplyr 1.0.0 dev) #5137

Closed
jasopolis opened this issue Apr 21, 2020 · 2 comments
Closed

Comments

@jasopolis
Copy link

@jasopolis jasopolis commented Apr 21, 2020

(I'm currently using the development version of dplyr 1.0.0 a.k.a. 0.8.99.9002)

With dplyr 1.0.0, I understand across() should supersede all scoped verbs, and the scoped select_all documentation now says "select_if() and rename_if() already use tidy selection so they can't be replaced by across() and instead we need a new function."

But when trying to use a purrr-style function with select(), I get an error, which otherwise works with the (now-deprecated) select_if().

Thanks -- here's a reprex!

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

df <- tibble(x = c(1,2,3), y = c(4,5,NA), 
             z = c(NA, NA, NA), a = c("1", "2", "3"))

select(df, is.numeric | contains("a"))
#> # A tibble: 3 x 3
#>       x     y a    
#>   <dbl> <dbl> <chr>
#> 1     1     4 1    
#> 2     2     5 2    
#> 3     3    NA 3

select(df, ~!all(is.na(.)))
#> Error: Must subset columns with a valid subscript vector.
#> x Subscript has the wrong type `formula`.
#> ℹ It must be numeric or character.

select_if(df, ~!all(is.na(.)))
#> # A tibble: 3 x 3
#>       x     y a    
#>   <dbl> <dbl> <chr>
#> 1     1     4 1    
#> 2     2     5 2    
#> 3     3    NA 3

Created on 2020-04-17 by the reprex package (v0.3.0)

@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Apr 23, 2020

@lionel- tidyselect gives:

library(tidyselect)
library(rlang)

tidyselect::eval_select(expr(is.numeric), mtcars)
#>  mpg  cyl disp   hp drat   wt qsec   vs   am gear carb 
#>    1    2    3    4    5    6    7    8    9   10   11
tidyselect::eval_select(expr(~is.numeric(.)), mtcars)
#> Error: Must subset columns with a valid subscript vector.
#> x Subscript has the wrong type `formula`.
#> ℹ It must be numeric or character.

Created on 2020-04-23 by the reprex package (v0.3.0)

@hadley
Copy link
Member

@hadley hadley commented Apr 25, 2020

Duplicate of r-lib/tidyselect#190

@hadley hadley marked this as a duplicate of r-lib/tidyselect#190 Apr 25, 2020
@hadley hadley closed this as completed Apr 25, 2020
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

No branches or pull requests

3 participants