Learn R Programming

lintr (version 3.1.0)

condition_message_linter: Block usage of paste() and paste0() with messaging functions using ...

Description

This linter discourages combining condition functions like stop() with string concatenation functions paste() and paste0(). This is because

Usage

condition_message_linter()

Arguments

Tags

best_practices, consistency

Details

  • stop(paste0(...)) is redundant as it is exactly equivalent to stop(...)

  • stop(paste(...)) is similarly equivalent to stop(...) with separators (see examples)

The same applies to the other default condition functions as well, i.e., warning(), message(), and packageStartupMessage().

See Also

linters for a complete list of linters available in lintr.

Examples

Run this code
# will produce lints
lint(
  text = 'stop(paste("a string", "another"))',
  linters = condition_message_linter()
)

lint(
  text = 'warning(paste0("a string", " another"))',
  linters = condition_message_linter()
)

# okay
lint(
  text = 'stop("a string", " another")',
  linters = condition_message_linter()
)

lint(
  text = 'warning("a string", " another")',
  linters = condition_message_linter()
)

lint(
  text = 'warning(paste("a string", "another", sep = "-"))',
  linters = condition_message_linter()
)

Run the code above in your browser using DataLab