silent_library function

Han Oostdijk

2020/02/15

Date last run: 15Feb2020

Example of messages shown by library

While writing a blog entry featuring silent_library I realized that I did not quit make clear what the reason was to create that function. In this entry I show the various ways that messages produced when loading a package can be handled.

In an rmarkdown entry as this one we have at least three (four) ways to handle messages when loading a package. After each load we detach the package (because otherwise the package would not be reloaded and messages would never appear) :

use library in a chunk with message=T

`​``{r message=T}
library(dplyr)
detach(pos=match('package:dplyr',search()))
`​`` 
#> Warning: package 'dplyr' was built under R version 3.6.2
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

use library in a chunk with message=F

`​``{r message=F}
library(dplyr)
detach(pos=match('package:dplyr',search()))
`​`` 
#> Warning: package 'dplyr' was built under R version 3.6.2

use HOQCutil::silent_library (with an arbitrary message chunk option)

`​``{r message=F}
HOQCutil::silent_library(dplyr)
detach(pos=match('package:dplyr',search()))
`​`` 

No messages !

`​``{r message=T}
HOQCutil::silent_library(dplyr)
detach(pos=match('package:dplyr',search()))
`​`` 

No messages !

Session Info

This document was produced on 15Feb2020 with the following R environment:

  #> R version 3.6.0 (2019-04-26)
  #> Platform: x86_64-w64-mingw32/x64 (64-bit)
  #> Running under: Windows 10 x64 (build 18362)
  #> 
  #> Matrix products: default
  #> 
  #> locale:
  #> [1] LC_COLLATE=English_United States.1252 
  #> [2] LC_CTYPE=English_United States.1252   
  #> [3] LC_MONETARY=English_United States.1252
  #> [4] LC_NUMERIC=C                          
  #> [5] LC_TIME=English_United States.1252    
  #> 
  #> attached base packages:
  #> [1] stats     graphics  grDevices utils     datasets  methods   base     
  #> 
  #> loaded via a namespace (and not attached):
  #>  [1] Rcpp_1.0.3       digest_0.6.23    HOQCutil_0.1.17  crayon_1.3.4    
  #>  [5] dplyr_0.8.4      assertthat_0.2.1 R6_2.4.1         magrittr_1.5    
  #>  [9] evaluate_0.14    pillar_1.4.3     rlang_0.4.4      stringi_1.4.5   
  #> [13] rmarkdown_2.1    tools_3.6.0      stringr_1.4.0    glue_1.3.1      
  #> [17] purrr_0.3.3      xfun_0.10        compiler_3.6.0   pkgconfig_2.0.3 
  #> [21] htmltools_0.4.0  tidyselect_0.2.5 knitr_1.28       tibble_2.1.3