
Last chance! 50% off unlimited learning
Sale ends in
Check that the c()
function is not used without arguments nor with a single constant.
unnecessary_concatenation_linter(allow_single_expression = TRUE)
Logical, default TRUE
. If FALSE
, one-expression
usages of c()
are always linted, e.g. c(x)
and c(matrix(...))
. In some such
cases, c()
is being used for its side-effect of stripping non-name attributes;
it is usually preferable to use the more readable as.vector()
instead.
as.vector()
is not always preferable, for example with environments
(especially, R6
objects), in which case list()
is the better alternative.
configurable, efficiency, readability, style
linters for a complete list of linters available in lintr.
# will produce lints
lint(
text = "x <- c()",
linters = unnecessary_concatenation_linter()
)
lint(
text = "x <- c(TRUE)",
linters = unnecessary_concatenation_linter()
)
lint(
text = "x <- c(1.5 + 2.5)",
linters = unnecessary_concatenation_linter(allow_single_expression = FALSE)
)
# okay
lint(
text = "x <- NULL",
linters = unnecessary_concatenation_linter()
)
# In case the intent here was to seed a vector of known size
lint(
text = "x <- integer(4L)",
linters = unnecessary_concatenation_linter()
)
lint(
text = "x <- TRUE",
linters = unnecessary_concatenation_linter()
)
lint(
text = "x <- c(1.5 + 2.5)",
linters = unnecessary_concatenation_linter(allow_single_expression = TRUE)
)
Run the code above in your browser using DataLab