简体   繁体   English

如何禁止将“S3 方法覆盖”消息打印到用户控制台

[英]how to suppress “S3 method overwritten” messages from being printed to user console

I have an R package called ggstatsplot ( https://indrajeetpatil.github.io/ggstatsplot/ ) which relies on a collection of packages that share a few S3 methods between each other. I have an R package called ggstatsplot ( https://indrajeetpatil.github.io/ggstatsplot/ ) which relies on a collection of packages that share a few S3 methods between each other. Therefore, every time the package is loaded, the user is bombarded with messages about this issue, which is not useful for the most users.因此,每次加载 package 时,用户都会收到有关此问题的消息轰炸,这对大多数用户来说没有用。

> library(ggstatsplot)
Registered S3 method overwritten by 'broom.mixed':
  method      from 
  tidy.gamlss broom
Registered S3 methods overwritten by 'car':
  method                          from
  influence.merMod                lme4
  cooks.distance.influence.merMod lme4
  dfbeta.influence.merMod         lme4
  dfbetas.influence.merMod        lme4

Is there something I can implement in the package internally to avoid these messages getting printed to the user's console?有什么我可以在 package 内部实现的东西,以避免这些消息被打印到用户的控制台? Maybe something using .onAttach ?也许使用.onAttach东西?

Quickly looked at the code of the package on GitHub, and to me it seems like some of those functions should be removed from NAMESPACE.快速查看 GitHub 上 package 的代码,在我看来,其中一些函数似乎应该从 NAMESPACE 中删除。

You are using @importFrom() however simply adding an "Imports:" declaration in DESCRIPTION and then calling the functions by specifying the namespace, ie package::function is enough.您正在使用@importFrom()但是只需在DESCRIPTION 中添加一个“Imports:”声明,然后通过指定命名空间来调用函数,即package::function就足够了。 This way they would not get attached to the namespace and would not conflict with one another.这样一来,它们就不会附加到命名空间,也不会相互冲突。


Looked a bit closer, and it seems that the issue is with the packages that you export, not your library itself.仔细看了一下,似乎问题出在您导出的包上,而不是您的库本身。 So for example simply calling library(broom.mixed) produces the conflicts.因此,例如简单地调用library(broom.mixed)会产生冲突。 Since you export some of its import (from broomExtra ) the same conflicts appear.由于您导出了它的一些导入(来自broomExtra ),因此会出现相同的冲突。

Seems like there is an issue about it already on their GitHub: HERE so best case would be to issue a pull request to them.似乎在他们的 GitHub 上已经存在一个问题:这里最好的情况是向他们发出拉取请求。 Or alternatively - maybe you don't really need to export those functions in the first place.或者,也许您实际上并不需要首先导出这些功能。

Therefore, every time the package is loaded, the user is bombarded with messages about this issue, which is not useful for the most users.因此,每次加载 package 时,用户都会收到有关此问题的消息轰炸,这对大多数用户来说没有用。

As a "peace of mind" workaround, users can simply set the environment variable _R_S3_METHOD_REGISTRATION_NOTE_OVERWRITES_ to one of 0 , no or false before loading any of the affected packages:作为一种“安心”的解决方法,用户可以在加载任何受影响的包之前简单地将环境变量_R_S3_METHOD_REGISTRATION_NOTE_OVERWRITES_设置0nofalse之一:

Sys.setenv(`_R_S3_METHOD_REGISTRATION_NOTE_OVERWRITES_` = "false")

Background: There was some instructive conversation about overwriting S3 methods becoming verbose with R 3.6 over at rlang's GitHub repo for anyone interested in more details.背景:对于任何对更多细节感兴趣的人,在 rlang 的 GitHub 存储库中有一些关于使用 R 3.6 覆盖 S3 方法变得冗长的指导性对话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM