Check that pipe operators are used consistently by file, or optionally specify one valid pipe operator.
Usage
pipe_consistency_linter(pipe = c("auto", "%>%", "|>"))
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()
)
#> <text>:1:5: style: [pipe_consistency_linter] Stick to one pipe operator; found 1 instances of %>% and 1 instances of |>.
#> 1:3 |> mean() %>% as.character()
#> ^~
#> <text>:1:15: style: [pipe_consistency_linter] Stick to one pipe operator; found 1 instances of %>% and 1 instances of |>.
#> 1:3 |> mean() %>% as.character()
#> ^~~
lint(
text = "1:3 %>% mean() %>% as.character()",
linters = pipe_consistency_linter("|>")
)
#> <text>:1:5: style: [pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
#> 1:3 %>% mean() %>% as.character()
#> ^~~
#> <text>:1:16: style: [pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
#> 1:3 %>% mean() %>% as.character()
#> ^~~
# okay
lint(
text = "1:3 %>% mean() %>% as.character()",
linters = pipe_consistency_linter()
)
#> ℹ No lints found.
lint(
text = "1:3 |> mean() |> as.character()",
linters = pipe_consistency_linter()
)
#> ℹ No lints found.