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)[ |
I can see how
as.character(x)can be preferable overx %>% as.character(), but I don't think the alternatives for other pipes work as well.Consider
%<>%(e.g.)This example lints:
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 ofdatais 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
%>%/|>:lintr/R/one_call_pipe_linter.R
Line 48 in 209e250