Learn R Programming

lintr (version 3.1.2)

expect_length_linter: Require usage of expect_length(x, n) over expect_equal(length(x), n)

Description

testthat::expect_length() exists specifically for testing the length() of an object. testthat::expect_equal() can also be used for such tests, but it is better to use the tailored function instead.

Usage

expect_length_linter()

Arguments

Tags

best_practices, package_development, pkg_testthat, readability

See Also

linters for a complete list of linters available in lintr.

Examples

Run this code
# will produce lints
lint(
  text = "expect_equal(length(x), 2L)",
  linters = expect_length_linter()
)

# okay
lint(
  text = "expect_length(x, 2L)",
  linters = expect_length_linter()
)

Run the code above in your browser using DataLab