Skip to contents

Check for duplicate arguments in function calls. Some cases are run-time errors (e.g. mean(x = 1:5, x = 2:3)), otherwise this linter is used to discourage explicitly providing duplicate names to objects (e.g. c(a = 1, a = 2)). Duplicate-named objects are hard to work with programmatically and should typically be avoided.

Usage

duplicate_argument_linter(except = c("mutate", "transmute"))

Arguments

except

A character vector of function names as exceptions. Defaults to functions that allow sequential updates to variables, currently dplyr::mutate() and dplyr::transmute().

See also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "list(x = 1, x = 2)",
  linters = duplicate_argument_linter()
)
#> ::warning file=<text>,line=1,col=13::file=<text>,line=1,col=13,[duplicate_argument_linter] Avoid duplicate arguments in function calls.

lint(
  text = "fun(arg = 1, arg = 2)",
  linters = duplicate_argument_linter()
)
#> ::warning file=<text>,line=1,col=14::file=<text>,line=1,col=14,[duplicate_argument_linter] Avoid duplicate arguments in function calls.

# okay
lint(
  text = "list(x = 1, x = 2)",
  linters = duplicate_argument_linter(except = "list")
)

lint(
  text = "df %>% dplyr::mutate(x = a + b, x = x + d)",
  linters = duplicate_argument_linter()
)