View source: R/class_equals_linter.R
class_equals_linter | R Documentation |
==
Usage like class(x) == "character"
is prone to error since class in R
is in general a vector. The correct version for S3 classes is inherits()
:
inherits(x, "character")
. Often, class k
will have an is.
equivalent,
for example is.character()
or is.data.frame()
.
class_equals_linter()
Similar reasoning applies for class(x) %in% "character"
.
best_practices, consistency, robustness
linters for a complete list of linters available in lintr.
# will produce lints
lint(
text = 'is_lm <- class(x) == "lm"',
linters = class_equals_linter()
)
lint(
text = 'if ("lm" %in% class(x)) is_lm <- TRUE',
linters = class_equals_linter()
)
# okay
lint(
text = 'is_lm <- inherits(x, "lm")',
linters = class_equals_linter()
)
lint(
text = 'if (inherits(x, "lm")) is_lm <- TRUE',
linters = class_equals_linter()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.