Conversation
|
Stefan prefers without parentheses. |
Yeah, IMO that's way cleaner and less typing. Also, I think more of RHS as functions/expressions, so like in that one does not write |
|
Thanks. A few thoughts:
How about a new section about omitting the parentheses for unary functions? |
|
Well the style guide is obviously not a very stylish guide in this case ;-) as I said, my opinion is not the only one, and I don't have to make all decisions. I don't see omission of |
|
#236 is another reason to teach users the longer form first: library(magrittr)
mtcars$cyl %>%
forcats::as_factor
#> Error in .::forcats: unused argument (as_factor)Created on 2020-12-05 by the reprex package (v0.3.0) What's a good way to move forward? |
|
Hi all, Thanks! |
|
FWIW, not including a function call produces a lint: library(lintr)
# will produce lints
lint(
text = "1:3 %>% mean %>% as.character",
linters = pipe_call_linter()
)
#> <text>:1:9: warning: [pipe_call_linter] Use explicit calls in magrittr pipes, i.e., `a %>% foo` should be `a %>% foo()`.
#> 1:3 %>% mean %>% as.character
#> ^~~~
#> <text>:1:18: warning: [pipe_call_linter] Use explicit calls in magrittr pipes, i.e., `a %>% foo` should be `a %>% foo()`.
#> 1:3 %>% mean %>% as.character
#> ^~~~~~~~~~~~
# okay
lint(
text = "1:3 %>% mean() %>% as.character()",
linters = pipe_call_linter()
)Created on 2022-10-11 with reprex v2.0.2 Additionally, native pipe requires a function call: library(lintr)
lint(
text = "1:3 |> mean |> as.character",
linters = pipe_call_linter()
)
#> <text>:1:1: error: [error] The pipe operator requires a function call as RHS
#>
#> ^Created on 2022-10-11 with reprex v2.0.2 For these reasons, I agree with Kirill here that the README should include function calls. |
in README.