Posted on Categories Programming, Statistics, TutorialsTags , ,

More Pipes in R

Was enjoying Gabriel’s article Pipes in R Tutorial For Beginners and wanted call attention to a few more pipes in R (not all for beginners).


NewImage

The Kleisli arrow Khaleesi and dragon.

3 thoughts on “More Pipes in R”

  1. Of course is one really wants to get up to mischief you can try unicode pipes:

    assign(paste0('%.', intToUtf8(10132), '%'), wrapr::`%.>%`)
    7 %.➔% sqrt(.)
    #> [1] 2.645751
    

    Bind that to a keyboard shortcut and you can make everybody jealous (note: UTF8 is not recommended in R source code).

    library("addinexamplesWV")
    options("addinexamplesWV.usrFn1" = 
              function() { 
                rstudioapi::insertText(paste0(' %.', 
                                              intToUtf8(10132), 
                                              '% ')) })
    

    Unfortunately this doesn’t directly work for magrittr (likely due to magrittr capturing source code and then directly looking for the names of pipe stages):

    assign(paste0('%', intToUtf8(10132), '%'), magrittr::`%>%`)
    7 %➔% sqrt
    #> Error in pipes[[i]]: subscript out of bounds
    
  2. There’s also the lumberjack package offering a pipe that actually does something extra useful: it allows you to log changes in data.

Comments are closed.