Skip to content

filter() silently accepting matrices  #5973

@romainfrancois

Description

@romainfrancois
library(dplyr, warn.conflicts = FALSE)

df <- data.frame(x = 1:2, y = 3:4)

this fails, as it should

filter(df, c(TRUE, TRUE, FALSE, FALSE))
#> Error: Problem with `filter()` input `..1`.
#> ℹ Input `..1` is `c(TRUE, TRUE, FALSE, FALSE)`.
#> x Input `..1` must be of size 2 or 1, not size 4.

but this does not fail, and worse it silently uses the first column of the matrix:

filter(df, matrix(c(TRUE, TRUE, TRUE, FALSE), nrow = 2))
#>   x y
#> 1 1 3
#> 2 2 4

however if we convert the matrix to a data frame, then
we get an auto splicing behavior

filter(df, as.data.frame(matrix(c(TRUE, TRUE, TRUE, FALSE), nrow = 2)))
#>   x y
#> 1 1 3

Created on 2021-08-06 by the reprex package (v2.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions