Skip to contents

Check that pipe operators are used consistently by file, or optionally specify one valid pipe operator.

Usage

pipe_consistency_linter(pipe = c("auto", "%>%", "|>"))

Arguments

pipe

Which pipe operator is valid (either "%>%" or "|>"). By default ("auto"), the linter has no preference but will check that each file uses only one type of pipe operator.

See also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "1:3 |> mean() %>% as.character()",
  linters = pipe_consistency_linter()
)
#> ::warning file=<text>,line=1,col=5::file=<text>,line=1,col=5,[pipe_consistency_linter] Found 1 instances of %>% and 1 instances of |>. Stick to one pipe operator.
#> ::warning file=<text>,line=1,col=15::file=<text>,line=1,col=15,[pipe_consistency_linter] Found 1 instances of %>% and 1 instances of |>. Stick to one pipe operator.

lint(
  text = "1:3 %>% mean() %>% as.character()",
  linters = pipe_consistency_linter("|>")
)
#> ::warning file=<text>,line=1,col=5::file=<text>,line=1,col=5,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
#> ::warning file=<text>,line=1,col=16::file=<text>,line=1,col=16,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.

# okay
lint(
  text = "1:3 %>% mean() %>% as.character()",
  linters = pipe_consistency_linter()
)

lint(
  text = "1:3 |> mean() |> as.character()",
  linters = pipe_consistency_linter()
)