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

View source: R/condition_message_linter.R

condition_message_linterR Documentation

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

  • 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().

Usage

condition_message_linter()

Tags

best_practices, consistency

See Also

linters for a complete list of linters available in lintr.

Examples

# 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()
)


r-lib/lintr documentation built on Dec. 20, 2024, 7:24 p.m.