Related to this question.
I\'d like to build a custom pipe %W>% that would silence warnings for one operation
library(magrittr)
data.
Coming back a little more experienced, I just missed an eval.parent and substitute combo, no need for rlang :
`%W>%` <- function(lhs,rhs){
w <- options()$warn
on.exit(options(warn=w))
options(warn=-1)
eval.parent(substitute(lhs %>% rhs))
}
data.frame(a= c(1,-1)) %W>% mutate(a=sqrt(a)) %>% cos
# a
# 1 0.5403023
# 2 NaN