Skip to content

filter() and data frame results, filter(across()) #4678

@romainfrancois

Description

@romainfrancois

when we get a data frame from an expression in filter() perhaps we should & all its columns, this would enable something like

library(dplyr, warn.conflicts = FALSE)

iris %>% 
  filter(across(starts_with("Sepal"), ~ . > 4))
#> Error: filter() expressions should return logical vectors of the same size as the group

iris %>% 
  filter(Sepal.Length > 4 & Sepal.Width > 4)
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1          5.7         4.4          1.5         0.4  setosa
#> 2          5.2         4.1          1.5         0.1  setosa
#> 3          5.5         4.2          1.4         0.2  setosa

iris %>% 
  filter_at(vars(starts_with("Sepal")), all_vars(. > 4))
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1          5.7         4.4          1.5         0.4  setosa
#> 2          5.2         4.1          1.5         0.1  setosa
#> 3          5.5         4.2          1.4         0.2  setosa

Created on 2019-12-30 by the reprex package (v0.3.0.9000)

This might be a better model than the current strategy of tricking ... into a single expression with all_exprs()

Metadata

Metadata

Labels

featurea feature request or enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions