简体   繁体   中英

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. Therefore, every time the package is loaded, the user is bombarded with messages about this issue, which is not useful for the most users.

> 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? Maybe something using .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.

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. 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. Since you export some of its import (from broomExtra ) the same conflicts appear.

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. 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.

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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