Skip to contents

Usage like lapply(x, sum) > 10 is awkward because the list must first be coerced to a vector for comparison. A function like vapply() should be preferred.

Usage

list_comparison_linter()

See also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "lapply(x, sum) > 10",
  linters = list_comparison_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[list_comparison_linter] The output of lapply(), a list(), is being coerced for comparison by `>`. Instead, use a mapper that generates a vector with the correct type directly, for example vapply(x, FUN, character(1L)) if the output is a string.

# okay
lint(
  text = "unlist(lapply(x, sum)) > 10",
  linters = list_comparison_linter()
)