tidyverse / magrittr

Improve the readability of R code with the pipe
https://magrittr.tidyverse.org
Other
957 stars 157 forks source link

Package qualifier `::` treated as function when missing parentheses #236

Open mlell opened 3 years ago

mlell commented 3 years ago
data("mtcars")
mtcars$cyl %>% forcats::as_factor()
##  [1] 6 6 4 6 8 6 8 4 4 6 6 8 8 8 8 8 8 4 4 4 4 8 8 8 8 4 4 4 8 6 8 4
## Levels: 4 6 8

mtcars$cyl %>% forcats::as_factor
## Error in .::forcats : unused argument (as_factor)

So ::is treated as the function name when the parentheses are missing. Is this on purpose or should it be fixed?

My version of magrittr is 2.0.1.

krlmlr commented 3 years ago

I'm seeing the same behavior with magrittr 1.5:

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)

I guess this is one of the reasons to always put parens after the function.

ggrothendieck commented 3 years ago

This works with no () after the function.

 mtcars$cyl %>% (forcats::as_factor)