Redirect is.numeric(x) || is.integer(x)
to just use is.numeric(x)
Source: R/is_numeric_linter.R
is_numeric_linter.Rd
is.numeric()
returns TRUE
when typeof(x)
is double
or integer
--
testing is.numeric(x) || is.integer(x)
is thus redundant.
Details
NB: This linter plays well with class_equals_linter()
, which can help
avoid further is.numeric()
equivalents like
any(class(x) == c("numeric", "integer"))
.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "is.numeric(y) || is.integer(y)",
linters = is_numeric_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[is_numeric_linter] is.numeric(x) is the same as is.numeric(x) || is.integer(x). Use is.double(x) to test for objects stored as 64-bit floating point.
lint(
text = 'class(z) %in% c("numeric", "integer")',
linters = is_numeric_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[is_numeric_linter] is.numeric(x) is the same as class(x) %in% c("integer", "numeric"). Use is.double(x) to test for objects stored as 64-bit floating point.
# okay
lint(
text = "is.numeric(y) || is.factor(y)",
linters = is_numeric_linter()
)
lint(
text = 'class(z) %in% c("numeric", "integer", "factor")',
linters = is_numeric_linter()
)