Closed
Description
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
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
hadley commentedon Dec 30, 2019
Yeah, that makes sense to me.
OTOH maybe
all_vars()
andany_vars()
should becomeacross_any()
andacross_all()
?romainfrancois commentedon Dec 30, 2019
... or we just need a function somewhere that would take a list of logical vector and
reduce&
them, so we use this around theacross()
call:Created on 2019-12-30 by the reprex package (v0.3.0.9000)
romainfrancois commentedon Dec 30, 2019
But still, given the way
across()
works with other verbs, this would not be surprising that :give the same result as :
hadley commentedon Dec 30, 2019
Yeah, I'd say implement the data frame method regardless, and we'll come back later to talk about the overall interface (I suspect we will want row version of all the existing cumulative and summarising functions)
`filter()` handles data frame results when all columns are logical ve…
`filter()` handles data frame results when all columns are logical ve…
`filter()` handles data frame results when all columns are logical ve…