Skip to contents

testthat::expect_named() exists specifically for testing the names() 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_named_linter()

See also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = 'expect_equal(names(x), "a")',
  linters = expect_named_linter()
)
#> <text>:1:1: warning: [expect_named_linter] expect_named(x, n) is better than expect_equal(names(x), n)
#> expect_equal(names(x), "a")
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~

# okay
lint(
  text = 'expect_named(x, "a")',
  linters = expect_named_linter()
)
#>  No lints found.

lint(
  text = 'expect_equal(colnames(x), "a")',
  linters = expect_named_linter()
)
#>  No lints found.

lint(
  text = 'expect_equal(dimnames(x), "a")',
  linters = expect_named_linter()
)
#>  No lints found.