expect_s3_class_linter: Require usage of 'expect_s3_class()'

View source: R/expect_s3_class_linter.R

expect_s3_class_linterR Documentation

Require usage of expect_s3_class()

Description

testthat::expect_s3_class() exists specifically for testing the class of S3 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_s3_class_linter()

Tags

best_practices, package_development, pkg_testthat

See Also

  • linters for a complete list of linters available in lintr.

  • expect_s4_class_linter()

Examples

# will produce lints
lint(
  text = 'expect_equal(class(x), "data.frame")',
  linters = expect_s3_class_linter()
)

lint(
  text = 'expect_equal(class(x), "numeric")',
  linters = expect_s3_class_linter()
)

# okay
lint(
  text = 'expect_s3_class(x, "data.frame")',
  linters = expect_s3_class_linter()
)

lint(
  text = 'expect_type(x, "double")',
  linters = expect_s3_class_linter()
)


r-lib/lintr documentation built on Dec. 20, 2024, 7:24 p.m.