Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Turning off dplyr messages when using dplyr functions in your own packages in R

I have written an R package that has a function that uses dplyr::group_by and dplyr::summarise. How do I ensure that users who use that function aren’t subjected to the summarise() has grouped output by ‘X’. You can override using the .groups argument. message?

I can of course turn the message off by setting options(dplyr.summarise.inform = FALSE) but I would think this isn’t good practice as it might turn off the options globally for anyone who loads the package. Is there a way I can turn off the message only for the function calls from my package?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If we don’t want to use options or .groups, can wrap with suppressMessages

library(dplyr)
suppressMessages(mtcars %>%
     group_by(cyl, vs) %>% 
     summarise(mpg = sum(mpg)))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading