Search code examples
rpackageroxygen2

How to suppress messages from a package dependency to my own package build?


My question is related to this question except that I'm looking to apply this specifically within a package that I am building. As such, I don't call library() to bring in packages my package depends on, but I am using the following roxygen2 setup (as an example):

#' @rawNamespace import(shiny, except = c(dataTableOutput, renderDataTable))
#' @import dplyr
#' @importFrom ggalt stat_xspline

My problem is that calling the ggalt package brings in the following undesirable message into the console when my package is loaded, and I would like R to suppress this:

Registered S3 methods overwritten by 'ggalt':
  method                  from   
  grid.draw.absoluteGrob  ggplot2
  grobHeight.absoluteGrob ggplot2
  grobWidth.absoluteGrob  ggplot2
  grobX.absoluteGrob      ggplot2
  grobY.absoluteGrob      ggplot2

As per the question I linked above, I could use suppressMessages() if I were calling that package using library(). But would I do so within the roxygen2 infrastructure? Is it possible to apply this within the #' @rawNamespace import() line somehow? I'm having trouble finding documentation about what arguments this function provides other than except.

I also note this question, but this seems more focused on the package development stage, whereas my issue is more for the end-user of my completed package having the message suppressed.


Solution

  • I can think of a way to do what you want, but I don't recommend that you use it. You may run into complaints from CRAN at some point if you do.

    Think of a user who is using one of those ggplot2 methods, who then loads your package. Your package will cause ggalt to load, and will change the implementation of those functions to the ones that override them. The user should be told about that. If they don't want to hear it (because this is part of a document, or something), then they should suppress the messages, you shouldn't.

    So, now you know why you shouldn't suppress them, here's how you could probably do it. Instead of importing stat_xspline from ggalt, make ggalt into a suggested package, and test for it and load it explicitly when you need it. The explicit load should allow you to suppress any messages that it generates.