6 ms·
Isn't the reason that magrittr was able to use that syntax that it already existed, so your proposal is a breaking change?
by johnmyleswhite 6y ago
Isn't the reason that magrittr was able to use that syntax that it already existed, so your proposal is a breaking change?
- wodenokoto 6y agoI thought %% was some sort of macro expansions and that is how magrittr creates pipes. But browsing through the magrittr github repo, it looks like they just define %>% and the other pipes as functions [1]. I don't actually know the relation between magrittr and the RStudio shortcut, but I've always assumed a shortcut for typing the pipe characters exist because RStudio employs Hadley Wichkham, who in turn is really big on tidyverse and pipes. Would %>% mean anything in R if you didn't import magrittr? [1] https://github.com/tidyverse/magrittr/blob/8b3d510f2a333b22401e8b7be44e0df2ad36ec6f/R/pipe.R#L130 https://github.com/tidyverse/magrittr/blob/8b3d510f2a333b224...
- kkoncevicius 6y agoAll %fun% constructs are just simple functions that can be created by the user and can be used as infix operators. Base R has a few of those: %in%, %o%, %*%, %x%, %%, %/%. magrittr created %>% which, when used in infix: x %>% f() calls the function on the right side with the argument on the left side f(x). There are package that provide tons more. For example: https://github.com/moodymudskipper/inops https://github.com/moodymudskipper/inops . And you can easily create your own: `%sum%` <- function(x, y) x + y 1 %sum% 2 [1] 3
- kilbuz 6y agoTo define a new binary operator in R (which are just functions), it must be between % characters. %>% does not mean anything in base R.