Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Article describing how to handle (and suppress) package startup messages #187

Closed
PeteHaitch opened this issue Mar 28, 2018 · 8 comments · Fixed by #271
Closed

Article describing how to handle (and suppress) package startup messages #187

PeteHaitch opened this issue Mar 28, 2018 · 8 comments · Fixed by #271
Labels
documentation good first issue ❤️ help wanted ❤️ tidy-dev-day 🤓

Comments

@PeteHaitch
Copy link

@PeteHaitch PeteHaitch commented Mar 28, 2018

I almost always want to wrap library() in suppressPackageStartupMessages() for my reprexes, but I always forget the first time around :( This is particularly true for Bioconductor packages, which tend to be very noisy because many depend on BiocGenerics (which masks a bunch of base function with equivalent S4 generics and reports this fact). For example, here I load the widely used SummarizedExperiment Bioconductor package:

library(SummarizedExperiment)
#> Loading required package: GenomicRanges
#> Loading required package: stats4
#> Loading required package: BiocGenerics
#> Loading required package: parallel
#> 
#> Attaching package: 'BiocGenerics'
#> The following objects are masked from 'package:parallel':
#> 
#>     clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
#>     clusterExport, clusterMap, parApply, parCapply, parLapply,
#>     parLapplyLB, parRapply, parSapply, parSapplyLB
#> The following objects are masked from 'package:stats':
#> 
#>     IQR, mad, sd, var, xtabs
#> The following objects are masked from 'package:base':
#> 
#>     anyDuplicated, append, as.data.frame, basename, cbind,
#>     colMeans, colnames, colSums, dirname, do.call, duplicated,
#>     eval, evalq, Filter, Find, get, grep, grepl, intersect,
#>     is.unsorted, lapply, lengths, Map, mapply, match, mget, order,
#>     paste, pmax, pmax.int, pmin, pmin.int, Position, rank, rbind,
#>     Reduce, rowMeans, rownames, rowSums, sapply, setdiff, sort,
#>     table, tapply, union, unique, unsplit, which, which.max,
#>     which.min
#> Loading required package: S4Vectors
#> 
#> Attaching package: 'S4Vectors'
#> The following object is masked from 'package:base':
#> 
#>     expand.grid
#> Loading required package: IRanges
#> Loading required package: GenomeInfoDb
#> Loading required package: Biobase
#> Welcome to Bioconductor
#> 
#>     Vignettes contain introductory material; view with
#>     'browseVignettes()'. To cite Bioconductor, see
#>     'citation("Biobase")', and for packages 'citation("pkgname")'.
#> Loading required package: DelayedArray
#> Loading required package: matrixStats
#> 
#> Attaching package: 'matrixStats'
#> The following objects are masked from 'package:Biobase':
#> 
#>     anyMissing, rowMedians
#> Loading required package: BiocParallel
#> 
#> Attaching package: 'DelayedArray'
#> The following objects are masked from 'package:matrixStats':
#> 
#>     colMaxs, colMins, colRanges, rowMaxs, rowMins, rowRanges
#> The following objects are masked from 'package:base':
#> 
#>     aperm, apply

Created on 2018-03-28 by the reprex package (v0.2.0).

Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                                             
#>  version  R Under development (unstable) (2018-03-05 r74359)
#>  system   x86_64, darwin15.6.0                              
#>  ui       X11                                               
#>  language (EN)                                              
#>  collate  en_AU.UTF-8                                       
#>  tz       America/New_York                                  
#>  date     2018-03-28
#> Packages -----------------------------------------------------------------
#>  package              * version   date       source        
#>  backports              1.1.2     2017-12-13 CRAN (R 3.5.0)
#>  base                 * 3.5.0     2018-03-06 local         
#>  Biobase              * 2.39.2    2018-01-25 Bioconductor  
#>  BiocGenerics         * 0.25.3    2018-02-09 Bioconductor  
#>  BiocParallel         * 1.13.3    2018-03-23 Bioconductor  
#>  bitops                 1.0-6     2013-08-17 CRAN (R 3.5.0)
#>  compiler               3.5.0     2018-03-06 local         
#>  datasets             * 3.5.0     2018-03-06 local         
#>  DelayedArray         * 0.5.22    2018-03-02 Bioconductor  
#>  devtools               1.13.5    2018-02-18 CRAN (R 3.5.0)
#>  digest                 0.6.15    2018-01-28 CRAN (R 3.5.0)
#>  evaluate               0.10.1    2017-06-24 CRAN (R 3.5.0)
#>  GenomeInfoDb         * 1.15.5    2018-02-04 Bioconductor  
#>  GenomeInfoDbData       1.1.0     2017-12-16 Bioconductor  
#>  GenomicRanges        * 1.31.23   2018-03-28 Bioconductor  
#>  graphics             * 3.5.0     2018-03-06 local         
#>  grDevices            * 3.5.0     2018-03-06 local         
#>  grid                   3.5.0     2018-03-06 local         
#>  htmltools              0.3.6     2017-04-28 CRAN (R 3.5.0)
#>  IRanges              * 2.13.28   2018-02-24 Bioconductor  
#>  knitr                  1.20      2018-02-20 CRAN (R 3.5.0)
#>  lattice                0.20-35   2017-03-25 CRAN (R 3.5.0)
#>  magrittr               1.5       2014-11-22 CRAN (R 3.5.0)
#>  Matrix                 1.2-12    2017-11-20 CRAN (R 3.5.0)
#>  matrixStats          * 0.53.1    2018-02-11 CRAN (R 3.5.0)
#>  memoise                1.1.0     2017-04-21 CRAN (R 3.5.0)
#>  methods              * 3.5.0     2018-03-06 local         
#>  parallel             * 3.5.0     2018-03-06 local         
#>  Rcpp                   0.12.16   2018-03-13 CRAN (R 3.5.0)
#>  RCurl                  1.95-4.10 2018-01-04 CRAN (R 3.5.0)
#>  rmarkdown              1.9       2018-03-01 CRAN (R 3.5.0)
#>  rprojroot              1.3-2     2018-01-03 CRAN (R 3.5.0)
#>  S4Vectors            * 0.17.38   2018-03-28 Bioconductor  
#>  stats                * 3.5.0     2018-03-06 local         
#>  stats4               * 3.5.0     2018-03-06 local         
#>  stringi                1.1.7     2018-03-12 CRAN (R 3.5.0)
#>  stringr                1.3.0     2018-02-19 CRAN (R 3.5.0)
#>  SummarizedExperiment * 1.9.16    2018-03-28 Bioconductor  
#>  tools                  3.5.0     2018-03-06 local         
#>  utils                * 3.5.0     2018-03-06 local         
#>  withr                  2.1.2     2018-03-15 CRAN (R 3.5.0)
#>  XVector                0.19.9    2018-02-28 Bioconductor  
#>  yaml                   2.1.18    2018-03-08 CRAN (R 3.5.0)
#>  zlibbioc               1.25.0    2017-10-31 Bioconductor

Created on 2018-03-28 by the reprex package (v0.2.0).

Yeeesh ...

I see reprex() has a tidyverse_quiet argument and that there was some discussion of the more general case in #70. Would you be amenable to revisiting this issue? I'd be happy to lead a PR.

Thanks for a very useful package!

@jennybc
Copy link
Member

@jennybc jennybc commented Mar 28, 2018

Hmm, yes, in my life the tidyverse package was the worst offender, so I took the easy way out there!

I am open to solving this more generally. Will you make another comment here, laying out the best options from #70 and I'll tag some others in to advise?

@cderv
Copy link
Contributor

@cderv cderv commented Mar 28, 2018

To share my experience, for all the messages about masked functions, I often use in my reprex the warn.conflicts = FALSE argument in library calls. For example, library(dplyr, warn.conflicts = FALSE) at the beginning of the reprex.

Moreover, there is also a quietly that I did not use for now. I do not know if any of this is enough for this bioconductor 📦 . I think it could suppress some of the messages and is kind of lighter than suppressPackageStartupMessages.

One solution could be to modify library calls to add those arguments if desired. The advantage I find is that this modification is not some magical suppression by reprex, but just the automatic activation of some already existing option. By magical, I imply not visible in code, in such way that if anyone copy the reprex, the messages would be there (even if not shown in the reprex code). I find it clearer if messages are deactivated explicitly.

@PeteHaitch
Copy link
Author

@PeteHaitch PeteHaitch commented Mar 28, 2018

@jennybc: Great, thanks. I'll do that

@cderv: Thanks for your thoughts. I'd not considered using arguments to library(). However, it appears that warn.conflicts = FALSE only warns of conflicts from the package argument, not its dependencies. E.g., library(BiocGenerics, warn.conflicts = FALSE) does not warn, but library(SummarizedExperiment, warn.conflicts = FALSE) emits warnings from BiocGenerics (an 'Import' of SummarizedExperiment https://github.com/Bioconductor/SummarizedExperiment/blob/master/DESCRIPTION#L16)

@cderv
Copy link
Contributor

@cderv cderv commented Mar 28, 2018

However, it appears that warn.conflicts = FALSE only warns of conflicts from the package argument, not its dependencies.

@PeteHaitch , Good to know! thanks for trying. library(SummarizedExperiment, warn.conflicts = FALSE, quietly = TRUE) does the same ?

@PeteHaitch
Copy link
Author

@PeteHaitch PeteHaitch commented Mar 28, 2018

Good to know! thanks for trying. library(SummarizedExperiment, warn.conflicts = FALSE, quietly = TRUE) does the same ?

It still produces a lot of output, and at a quick glance I can't tell what (if anything) is different from when quietly = FALSE. Will keep digging

@jennybc
Copy link
Member

@jennybc jennybc commented Mar 28, 2018

I have found quietly to be rather disappointing in the past @PeteHaitch. I don't think it's going to help us here.

@cderv
Copy link
Contributor

@cderv cderv commented Mar 29, 2018

Sorry for misleading here with quietly try - no need to dig further I think. Personally, warn.conflicts = FALSE is useful, quietly not so much - I observed in the past the same unclear behavior.

The proposition in previous issue of adding a #+ message = FALSE chunk option is an easy one so suppress only library calls. However, I fear that it also would suppress some messages useful for debugging in the reprex.

The other solution to call knit inside a suppressPackageStartupMessages call could solve it too without the drawbacks. I find this solution not so difficult to implement I think.

@jennybc
Copy link
Member

@jennybc jennybc commented May 17, 2019

I don't really see an attractive way to fix this in reprex.

I suggest an article showing the things a user can do to suppress these messages, so we can all link to it or re-read it when we need a refresher.

@jennybc jennybc changed the title Option to suppress package startup messages Article describing how to handle (and suppress) package startup messages May 17, 2019
@jennybc jennybc added documentation good first issue ❤️ help wanted ❤️ tidy-dev-day 🤓 labels May 17, 2019
marionlouveaux added a commit to marionlouveaux/reprex that referenced this issue Jul 8, 2019
marionlouveaux pushed a commit to marionlouveaux/reprex that referenced this issue Jul 8, 2019
marionlouveaux added a commit to marionlouveaux/reprex that referenced this issue Jul 8, 2019
marionlouveaux added a commit to marionlouveaux/reprex that referenced this issue Jul 27, 2019
- Adding quick syntax reminder
- Removing the startuppackage
- Revealing chunk code
- Modifying paragraph about tidyverse_quiet

Issue tidyverse#187
marionlouveaux added a commit to marionlouveaux/reprex that referenced this issue Jul 27, 2019
- Using package instead of library
- Using attach instead of load
- Removing {} around packages names
- Setting tidyverse_quiet to FALSE
- Adding .Rprofile configuration info

Issue tidyverse#187
@jennybc jennybc closed this in #271 Jul 28, 2019
jennybc pushed a commit that referenced this issue Jul 28, 2019
* Suppress startup messages: init article

Issue #187

* startup messages: add reprex of fake package for tests

#187

* Suppress startup messages: writing article

Issue #187

* Suppress startup messages: corrections

- Adding quick syntax reminder
- Removing the startuppackage
- Revealing chunk code
- Modifying paragraph about tidyverse_quiet

Issue #187

* Suppress startup messages: corrections

- Using package instead of library
- Using attach instead of load
- Removing {} around packages names
- Setting tidyverse_quiet to FALSE
- Adding .Rprofile configuration info

Issue #187

* Rename file

* Shorten title

* Work on the article

* Add NEWS bullet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation good first issue ❤️ help wanted ❤️ tidy-dev-day 🤓
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants