Skip to content

vector_logic_linter() false positive with && in mapping/apply #2935

@jmbarbone

Description

@jmbarbone

Example below uses && within a call to vapply() which prevents warnings/errors

packageVersion("lintr")
#> [1] '3.2.0.9000'
library(lintr)

example <- expression(
  tibble::tibble(
    id = 1:4,
    x = list(a = 1:2, b = 3:4, c = NULL, d = "a")
  ) |>
    dplyr::filter(
      vapply(x, function(i) is.numeric(i) && mean(i) > 1, NA)
    )
)

lint(
  text = as.character(example),
  linters = list(vector_logic_linter())
)
#> <text>:1:124: warning: [vector_logic_linter] Use `&` in subsetting expressions.
#> dplyr::filter(tibble::tibble(id = 1:4, x = list(a = 1:2, b = 3:4, c = NULL, d = "a")), vapply(x, function(i) is.numeric(i) && mean(i) > 1, NA))
#>                                                                                                                            ^~

Created on 2025-09-25 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions