1
votes

(I'm currently using the development version of dplyr 1.0.0)

With dplyr 1.0.0, the across() should supersede all scoped verbs. But when I try to use a purrr-style function with select(), the way you can with select_if(), it gives an error, and the only workaround I've found is to use the superseded select_if().

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."

Any advice? Thanks in advance!

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)

1
why can't select_if used - akrun
If you are having issues with the development version of a package, it's probably better to raise an issue on their github page. github.com/tidyverse/dplyr/issues - MrFlick
There is an open issue about this: github.com/r-lib/tidyselect/issues/187 - Lionel Henry

1 Answers

0
votes

We could pass a regular anonymous function on select

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