View source: R/literal_coercion_linter.R
literal_coercion_linter | R Documentation |
as.integer(1)
(or rlang::int(1)
) is the same as 1L
but the latter is
more concise and gets typed correctly at compilation.
literal_coercion_linter()
The same applies to missing sentinels like NA
– typically, it is not
necessary to specify the storage type of NA
, but when it is, prefer
using the typed version (e.g. NA_real_
) instead of a coercion
(like as.numeric(NA)
).
best_practices, consistency, efficiency
linters for a complete list of linters available in lintr.
# will produce lints
lint(
text = "int(1)",
linters = literal_coercion_linter()
)
lint(
text = "as.character(NA)",
linters = literal_coercion_linter()
)
lint(
text = "rlang::lgl(1L)",
linters = literal_coercion_linter()
)
# okay
lint(
text = "1L",
linters = literal_coercion_linter()
)
lint(
text = "NA_character_",
linters = literal_coercion_linter()
)
lint(
text = "TRUE",
linters = literal_coercion_linter()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.