Learn R Programming

lintr (version 3.1.2)

assignment_linter: Assignment linter

Description

Check that <- is always used for assignment.

Usage

assignment_linter(
  allow_cascading_assign = TRUE,
  allow_right_assign = FALSE,
  allow_trailing = TRUE,
  allow_pipe_assign = FALSE
)

Arguments

allow_cascading_assign

Logical, default TRUE. If FALSE, <<- and ->> are not allowed.

allow_right_assign

Logical, default FALSE. If TRUE, -> and ->> are allowed.

allow_trailing

Logical, default TRUE. If FALSE then assignments aren't allowed at end of lines.

allow_pipe_assign

Logical, default FALSE. If TRUE, magrittr's %<>% assignment is allowed.

Tags

configurable, consistency, default, style

See Also

Examples

Run this code
# will produce lints
lint(
  text = "x = mean(x)",
  linters = assignment_linter()
)

code_lines <- "1 -> x\n2 ->> y"
writeLines(code_lines)
lint(
  text = code_lines,
  linters = assignment_linter()
)

lint(
  text = "x %<>% as.character()",
  linters = assignment_linter()
)

# okay
lint(
  text = "x <- mean(x)",
  linters = assignment_linter()
)

code_lines <- "x <- 1\ny <<- 2"
writeLines(code_lines)
lint(
  text = code_lines,
  linters = assignment_linter()
)

# customizing using arguments
code_lines <- "1 -> x\n2 ->> y"
writeLines(code_lines)
lint(
  text = code_lines,
  linters = assignment_linter(allow_right_assign = TRUE)
)

lint(
  text = "x <<- 1",
  linters = assignment_linter(allow_cascading_assign = FALSE)
)

writeLines("foo(bar = \n 1)")
lint(
  text = "foo(bar = \n 1)",
  linters = assignment_linter(allow_trailing = FALSE)
)

lint(
  text = "x %<>% as.character()",
  linters = assignment_linter(allow_pipe_assign = TRUE)
)

Run the code above in your browser using DataLab