paste_linter | R Documentation |
paste()
The following issues are linted by default by this linter (see arguments for which can be de-activated optionally):
paste_linter(
allow_empty_sep = FALSE,
allow_to_string = FALSE,
allow_file_path = c("double_slash", "always", "never")
)
allow_empty_sep |
Logical, default |
allow_to_string |
Logical, default |
allow_file_path |
String, one of |
Block usage of paste()
with sep = ""
. paste0()
is a faster, more concise alternative.
Block usage of paste()
or paste0()
with collapse = ", "
. toString()
is a direct
wrapper for this, and alternatives like glue::glue_collapse()
might give better messages for humans.
Block usage of paste0()
that supplies sep=
– this is not a formal argument to paste0
, and
is likely to be a mistake.
Block usage of paste()
/ paste0()
combined with rep()
that could be replaced by
strrep()
. strrep()
can handle the task of building a block of repeated strings
(e.g. often used to build "horizontal lines" for messages). This is both more readable and
skips the (likely small) overhead of putting two strings into the global string cache when only one is needed.
Only target scalar usages – strrep
can handle more complicated cases (e.g. strrep(letters, 26:1)
,
but those aren't as easily translated from a paste(collapse=)
call.
best_practices, configurable, consistency
linters for a complete list of linters available in lintr.
# will produce lints
lint(
text = 'paste("a", "b", sep = "")',
linters = paste_linter()
)
lint(
text = 'paste(c("a", "b"), collapse = ", ")',
linters = paste_linter()
)
lint(
text = 'paste0(c("a", "b"), sep = " ")',
linters = paste_linter()
)
lint(
text = 'paste0(rep("*", 10L), collapse = "")',
linters = paste_linter()
)
lint(
text = 'paste0("http://site.com/", path)',
linters = paste_linter(allow_file_path = "never")
)
# okay
lint(
text = 'paste0("a", "b")',
linters = paste_linter()
)
lint(
text = 'paste("a", "b", sep = "")',
linters = paste_linter(allow_empty_sep = TRUE)
)
lint(
text = 'toString(c("a", "b"))',
linters = paste_linter()
)
lint(
text = 'paste(c("a", "b"), collapse = ", ")',
linters = paste_linter(allow_to_string = TRUE)
)
lint(
text = 'paste(c("a", "b"))',
linters = paste_linter()
)
lint(
text = 'strrep("*", 10L)',
linters = paste_linter()
)
lint(
text = 'paste0(year, "/", month, "/", day)',
linters = paste_linter(allow_file_path = "always")
)
lint(
text = 'paste0("http://site.com/", path)',
linters = paste_linter()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.