如何使 dplyr 中的连接操作静音? [英] How to make join operations in dplyr silent?

查看:20
本文介绍了如何使 dplyr 中的连接操作静音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dplyr (version 0.4.1) 打印它执行连接的列名.是否可以关闭此选项?

dplyr (version 0.4.1) prints the colnames by which it is performing the join. Is it possible to turn this option off?

R 代码:

library(dplyr)
a=data.frame(x=1,y=2)
b=data.frame(x=1,z=10)
aa=inner_join(a,b)

对于最后一行,dplyr 打印:

for the last line, dplyr prints:

Joining by: "x"

这对交互式工作很好,但我在 Rscript 中运行,所有这些行都阻塞了我的屏幕.

that is nice for interactive work, but I am running in Rscript and all these lines are clogging my screen.

推荐答案

如果你想大手大脚,你可以这样做

If you want to be heavy-handed, you can do

aa = suppressMessages(inner_join(a, b))

正如 Jazzurro 建议的那样,更好的选择是指定 by 参数.dplyr 只打印一条消息,让您知道它对要加入的列的猜测.如果你不让它猜测,它就不会与你确认事情.从防御性编码的角度来看,这也是一个更安全的选择.

The better choice, as Jazzurro suggests, is to specify the by argument. dplyr only prints a message to let you know what its guess is for which columns to join by. If you don't make it guess, it doesn't confirm things with you. This is a safer choice as well, from defensive coding standpoint.

如果这是在 knitr 文档中,您可以设置块选项 message=FALSE.

If this is in a knitr document, you can set the chunk option message=FALSE.

这篇关于如何使 dplyr 中的连接操作静音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆