Skip to content

Should one_call_pipe_linter() apply only to %>%? #2330

@IndrajeetPatil

Description

@IndrajeetPatil

I can see how as.character(x) can be preferable over x %>% as.character(), but I don't think the alternatives for other pipes work as well.

Consider %<>% (e.g.)

This example lints:

library(lintr)
lint(text = "data %<>% mutate(n.obs = n)", linters = one_call_pipe_linter())
#> <text>:1:2: warning: [one_call_pipe_linter] Expressions with only a single call shouldn't use pipe %<>%.
#>  data %<>% mutate(n.obs = n)
#>  ^~~~~~~~~~~~~~~~~~~~~~~~~~~

Created on 2023-11-21 with reprex v2.0.2

To avoid this, I instead need to do data <- mutate(data, n.obs = n), and avoiding repetition of data is the entire raison d'etre of %<>%. So when {lintr} says one shouldn't use this pipe only with a single call, it's basically saying don't use this pipe for the very thing for which it was built. That's not the case for %>%/|>. I hope I am being cogent here.

I could imagine a similar argument for other pipes.


So I am wondering if the following should be changed only to cover %>%/|>:

(//SPECIAL[{pipes_cond}] | //PIPE)[

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions