相关疑难解决方法(0)

定制管道以消除警告

此问题相关.

我想构建一个自定义管道%W>%,可以使一个操作的警告静音

library(magrittr)
data.frame(a= c(1,-1)) %W>% mutate(a=sqrt(a)) %>% cos
Run Code Online (Sandbox Code Playgroud)

将相当于:

w <- options()$warn
data.frame(a= c(1,-1)) %T>% {options(warn=-1)} %>%
  mutate(a=sqrt(a))    %T>% {options(warn=w)}  %>%
  cos
Run Code Online (Sandbox Code Playgroud)

这两次尝试不起作用:

`%W>%` <- function(lhs,rhs){
  w <- options()$warn
  on.exit(options(warn=w))
  options(warn=-1)
  lhs %>% rhs
}

`%W>%` <- function(lhs,rhs){
  lhs <- quo(lhs)
  rhs <- quo(rhs)
  w <- options()$warn
  on.exit(options(warn=w))
  options(warn=-1)
  (!!lhs) %>% (!!rhs)
}
Run Code Online (Sandbox Code Playgroud)

我怎么能把rlang它变成有效的东西呢?

r dplyr magrittr rlang

13
推荐指数
1
解决办法
636
查看次数

标签 统计

dplyr ×1

magrittr ×1

r ×1

rlang ×1