Check that integers are explicitly typed using the form 1L
instead of 1
.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "x <- 1",
linters = implicit_integer_linter()
)
#> <text>:1:7: style: [implicit_integer_linter] Use 1L or 1.0 to avoid implicit integers.
#> x <- 1
#> ~^
lint(
text = "x[2]",
linters = implicit_integer_linter()
)
#> <text>:1:4: style: [implicit_integer_linter] Use 2L or 2.0 to avoid implicit integers.
#> x[2]
#> ~^
lint(
text = "1:10",
linters = implicit_integer_linter()
)
#> <text>:1:2: style: [implicit_integer_linter] Use 1L or 1.0 to avoid implicit integers.
#> 1:10
#> ~^
#> <text>:1:5: style: [implicit_integer_linter] Use 10L or 10.0 to avoid implicit integers.
#> 1:10
#> ~~^
# okay
lint(
text = "x <- 1.0",
linters = implicit_integer_linter()
)
#> ℹ No lints found.
lint(
text = "x <- 1L",
linters = implicit_integer_linter()
)
#> ℹ No lints found.
lint(
text = "x[2L]",
linters = implicit_integer_linter()
)
#> ℹ No lints found.
lint(
text = "1:10",
linters = implicit_integer_linter(allow_colon = TRUE)
)
#> ℹ No lints found.