5 ms·
Kind of odd they didn't decide to go with the magrittr syntax, which is in common use and heavily promoted in dplyr / tidyverse. I wonder if RStudio will chang
by wodenokoto 6y ago
Kind of odd they didn't decide to go with the magrittr syntax, which is in common use and heavily promoted in dplyr / tidyverse.
I wonder if RStudio will change its `ctrl` + `shift` + m shortcut from the magrittr ( %>% ) style pipes to these new pipes ( |> )
- grayclhn 6y agoI'm pretty happy that they didn't, because silently replacing one operation with a similar operation that inevitably has different bugs and different ways of handling edge cases would be pretty frustrating. Letting both live side-by-side as people transition would be my preference.
- johnmyleswhite 6y agoIsn'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.
- SubiculumCode 6y agoargh. and here I've been typing %>%. thanks!!! also just discovered that ctrl shift m in firefox does something weird, looks like mobile view or something..
- creddit 6y agoYou can't do that if you wanted it to be a symbol of its own. The use of wrapping "%" is native functionality so making `%>%` into a symbol would break the consistency of that.
- vharuck 6y agoI'm sure they wanted to not replace magrittr pipes. R is introspective, and some reckless people (like myself) will mess with functions' guts in a few scripts. Replacing the `%>%` function with a syntax symbol will break those scripts. Even with scripts that don't metaphorically shove their hands down the garbage disposal, programmers might've relied on certain behaviors of the magrittr pipe. The R Core team is very cautious about breaking anything, including universally acknowledged terrible defaults (I never thought `stringsAsFactors = TRUE` would ever go away). They know the majority of R programmers are not experts in programming. These users just want to write a script, debug it, and then use it for years with complete trust in the results.
- ImaCake 6y agoIt seems to have been worth the caution. R has a great reputation for stability. The contrast between my experiences in R and python datascience tools is stark. Pandas syntax has changed wildly since I started learning it, but R and tidyverse hasn’t really changed at all. Admittedly pandas was in rapid and early development at the time.
- disgruntledphd2 6y agoI think the R reputation for stability is entirely driven by CRAN. If your package doesn't build on the latest version of R, it is marked unavailable. This means that people can build on R-current, in a way that simply isn't possible with the state of python packaging. Maybe Python just needs a bigger repository with more stringent rules for what will be allowed?
- vharuck 6y agoCRAN is definitely one of the best "features" of R. A very strict and official repository that requires human approval. Most often, that human is part of or close to the R Core team. Most guides I've read for getting a package on CRAN have to mention not wasting the time of somebody who's likely a busy statistics professor.