View source: R/nzchar_linter.R
nzchar_linter | R Documentation |
nzchar()
efficiently determines which of a vector of strings are empty
(i.e., are ""
). It should in most cases be used instead of
constructions like string == ""
or nchar(string) == 0
.
nzchar_linter()
One crucial difference is in the default handling of NA_character_
, i.e.,
missing strings. nzchar(NA_character_)
is TRUE
, while NA_character_ == ""
and nchar(NA_character_) == 0
are both NA
. Therefore, for strict
compatibility, use nzchar(x, keepNA = TRUE)
. If the input is known to be
complete (no missing entries), this argument can be dropped for conciseness.
best_practices, consistency, efficiency
linters for a complete list of linters available in lintr.
# will produce lints
lint(
text = "x[x == '']",
linters = nzchar_linter()
)
lint(
text = "x[nchar(x) > 0]",
linters = nzchar_linter()
)
# okay
lint(
text = "x[!nzchar(x, keepNA = TRUE)]",
linters = nzchar_linter()
)
lint(
text = "x[nzchar(x, keepNA = TRUE)]",
linters = nzchar_linter()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.