Skip to content

Emphasize that filter(x, A, B) is not strictly the same as filter(filter(x, A), B) #6968

@MichaelChirico

Description

@MichaelChirico

Have had to re-confirm this for myself a few times:

filter(mtcars, cyl < max(cyl), hp < max(hp)) |> dim()
# [1] 18 11

# vs
filter(filter(mtcars, cyl < max(cyl)), hp < max(hp)) |> dim()
# [1] 17 11

This in ?dplyr hints at what's going on:

If multiple expressions are included, they are combined with the & operator.

But this behavior is a bit more subtle / worth calling out IMO. This came up again recently here:

r-lib/lintr#2305 (comment)

FWIW it's also really not clear from reading the filter.data.frame implementation without being well-versed in {dplyr} internals.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions