Require usage of expect_length(x, n)
over expect_equal(length(x), n)
Source: R/expect_length_linter.R
expect_length_linter.Rd
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.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "expect_equal(length(x), 2L)",
linters = expect_length_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[expect_length_linter] expect_length(x, n) is better than expect_equal(length(x), n)
# okay
lint(
text = "expect_length(x, 2L)",
linters = expect_length_linter()
)