Learn R Programming

lintr (version 3.1.2)

is_numeric_linter: Redirect is.numeric(x) || is.integer(x) to just use is.numeric(x)

Description

is.numeric() returns TRUE when typeof(x) is double or integer -- testing is.numeric(x) || is.integer(x) is thus redundant.

Usage

is_numeric_linter()

Arguments

Tags

best_practices, consistency, readability

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

Run this code
# will produce lints
lint(
  text = "is.numeric(y) || is.integer(y)",
  linters = is_numeric_linter()
)

lint(
  text = 'class(z) %in% c("numeric", "integer")',
  linters = is_numeric_linter()
)

# 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()
)

Run the code above in your browser using DataLab