magrittr pipe operator does not work with dot notation when inside a user defined operator

Viewed 36

I'm having problems when creating a new operator that uses the magrittr pipe. It works well, just not with dot notation. Is there a simple way to make this work? Thanks!

`%>>>%` <- function(lhs, rhs) {
    lhs <- paste0(lhs, "hello")
    return(lhs %>% rhs)
}

"hello" %>>>% print
# [1] "hellohello"

"hello" %>>>% print(.)
# Error in print(.) : object '.' not found
1 Answers

One possible way to solve your problem:

`%>>>%` <- function(lhs, rhs) {
  lhs <- paste0(lhs, "hello")
  return(eval(substitute(lhs %>% rhs)))
}

"hello" %>>>% print
[1] "hellohello"

"hello" %>>>% print(.)
[1] "hellohello"
Related