Related to this question.
I\'d like to build a custom pipe %W>% that would silence warnings for one operation
library(magrittr)
data.
I'm not sure this solution works perfectly, but it's a start:
`%W>%` <- function(lhs, rhs) {
call <- substitute(`%>%`(lhs, rhs))
eval(withr::with_options(c("warn" = -1), eval(call)), parent.frame())
}
This seems to work for the following 2 examples:
> data.frame(a= c(1,-1)) %W>% mutate(a=sqrt(a)) %>% cos
a
1 0.5403023
2 NaN
> c(1,-1) %W>% sqrt()
[1] 1 NaN