2

I'm using magrittr to use the new piping functionality, and while I can use %>%, I can't use %,%. I tried the bottom example in the answer to

What is the difference between %>% and %,% in magrittr?

but I get the error Error in eval(expr, envir, enclos) : could not find function "%,%" Can someone who can get this function to work just paste the source code so I can

`%,% <- function(...

somehow. I'm trying to just use the paste function with multiple arguments, for example I want to replace

todaysDate <- as.numeric(paste(str_sub(Sys.time(),1,4),str_sub(Sys.time(),6,7),str_sub(Sys.time(),9,10),sep=''))

with

str_sub(Sys.time(),1,4) %,% str_sub(Sys.time(),6,7) %,% str_sub(Sys.time(),9,10) %>%
paste(sep='') %>% 
as.numeric()
Error in eval(expr, envir, enclos) : could not find function "%,%"

but instead I have to do

paste(str_sub(Sys.time(),1,4),str_sub(Sys.time(),6,7),str_sub(Sys.time(),9,10),sep='') %>%
as.numeric()
[1] 20141008

any help? (This is just an example function. I know paste(sep='') can be replaced with paste0(), etc.)

Community
  • 1
  • 1
hedgedandlevered
  • 2,314
  • 2
  • 25
  • 54
  • do you have the latest version of magrittr? – baptiste Oct 08 '14 at 16:37
  • I just installed it from CRAN this morning – hedgedandlevered Oct 08 '14 at 16:38
  • Notice the top of that question starts out: "Github developmental version ". Voting to close as reader-error. – IRTFM Oct 08 '14 at 16:38
  • oh, I figured it was (supposed to be) part of the magrittr package. I heard about this from http://www.r-statistics.com/2014/08/simpler-r-coding-with-pipes-the-present-and-future-of-the-magrittr-package/ and it doesn't mention that %,% is not yet implemented... – hedgedandlevered Oct 08 '14 at 16:41
  • voting to close seems a bit extreme, there's no indication anywhere that this should be only in the developmental version, and just because that guy happened to be using the dev version does not mean that this is the reason for this error. Did you check to see if this is reproducible? – hedgedandlevered Oct 08 '14 at 16:42
  • (There _was_ an indication at the top of the referenced SO question which I quoted.) I'm only voting to close because people never seem to delete the questions that have a simple answer in comments and are unlikely to be helpful when the development version eventually ends up on CRAN. I think you can still delete which would IMO be a better strategy. – IRTFM Oct 08 '14 at 16:46
  • yes, sorry I was unclear, I see that there was an indication in the SO question, I meant as far as in the general documentation I've seen when googling doesn't seem to mention that %,% is any newer than %>% so I could see how this would be a common mistake, and this would be appropriate for deletion only when it is added to the standard install.packages() default. Since there haven't been updates in 2 months, its possible that won't happen for some time, so this might help others. – hedgedandlevered Oct 08 '14 at 16:53

2 Answers2

2

%,% was defined in June, version 1.1.0 magrittr, while the current CRAN version is 1.0.1 (last update in May).

Arguably the easiest way to install packages on github is using devtools,

library(devtools)
install_github("smbache/magrittr")
baptiste
  • 75,767
  • 19
  • 198
  • 294
1

The %,% operator never made it to the CRAN version, as we decided to go with a better solution. Now %>% will create a function if the left-most left-hand side is the dot placeholder:

trigger <- . %>% sin %>% cos %>% tan

This is available in v1.5 on CRAN now.

Stefan
  • 1,835
  • 13
  • 20