Skip to contents

Check that integers are explicitly typed using the form 1L instead of 1.

Usage

implicit_integer_linter(allow_colon = FALSE)

Arguments

allow_colon

Logical, default FALSE. If TRUE, expressions involving : won't throw a lint regardless of whether the inputs are implicitly integers.

See also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "x <- 1",
  linters = implicit_integer_linter()
)
#> ::warning file=<text>,line=1,col=7::file=<text>,line=1,col=7,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles.

lint(
  text = "x[2]",
  linters = implicit_integer_linter()
)
#> ::warning file=<text>,line=1,col=4::file=<text>,line=1,col=4,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles.

lint(
  text = "1:10",
  linters = implicit_integer_linter()
)
#> ::warning file=<text>,line=1,col=2::file=<text>,line=1,col=2,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles.
#> ::warning file=<text>,line=1,col=5::file=<text>,line=1,col=5,[implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles.

# okay
lint(
  text = "x <- 1.0",
  linters = implicit_integer_linter()
)

lint(
  text = "x <- 1L",
  linters = implicit_integer_linter()
)

lint(
  text = "x[2L]",
  linters = implicit_integer_linter()
)

lint(
  text = "1:10",
  linters = implicit_integer_linter(allow_colon = TRUE)
)