Skip to contents

testthat::expect_type() exists specifically for testing the storage type of objects. testthat::expect_equal(), testthat::expect_identical(), and testthat::expect_true() can also be used for such tests, but it is better to use the tailored function instead.

Usage

expect_type_linter()

See also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = 'expect_equal(typeof(x), "double")',
  linters = expect_type_linter()
)
#> <text>:1:1: warning: [expect_type_linter] expect_type(x, t) is better than expect_equal(typeof(x), t)
#> expect_equal(typeof(x), "double")
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lint(
  text = 'expect_identical(typeof(x), "double")',
  linters = expect_type_linter()
)
#> <text>:1:1: warning: [expect_type_linter] expect_type(x, t) is better than expect_identical(typeof(x), t)
#> expect_identical(typeof(x), "double")
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# okay
lint(
  text = 'expect_type(x, "double")',
  linters = expect_type_linter()
)
#>  No lints found.