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()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[expect_type_linter] expect_type(x, t) is better than expect_equal(typeof(x), t)

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

# okay
lint(
  text = 'expect_type(x, "double")',
  linters = expect_type_linter()
)