A clean sessionInfo page

Writing a technical or academic report, or even a presentation, it is sensible to render the (R) code in such a writing reproducible. Same thing applies when asking for help at StackOverflow: you’ll be asked for a reprex.

One aspect for rendering a report reproducible is to include details on the version of packages needed. The well-known command sessionInf() provides the building blocks for that. However, the output of that function can feel verbose, and it consumes a lot of space.

A similar functionality is provided by sessioninfo::session_info(), is also allows for a more fine grained control of the output. However, it also can provide too much information when called without fine tuning. It also does not line wrap its output:

Maybe a cleaner output is achieved if we print only the packages along with their versions, and that as normal text, not formatted as R output.

As an example, let’s load some arbitrary packages.

library(tidyverse)
library(mosaic)
library(plotly)
library(ggrepel)
library(knitr)
library(DiagrammeR)

Then let’s extract the loaded packages along with their versions.

si <- sessioninfo::session_info()
pckgs <- map2(si$packages$package, 
              si$packages$loadedversion,
     ~ paste0(.x, " ", .y)) %>% 
  simplify()

Finally, print the stuff using this inline code:

- Date: `r si$platform$date`
- Packages: `r pckgs`
- OS: `r si$platform$os`
- Version: `r si$platform$version`

And that’s how it could look like:

  • Date: 2019-01-14
  • OS: macOS 10.14.2
  • Version: R version 3.5.1 (2018-07-02)
  • Packages: assertthat 0.2.0, backports 1.1.3, blogdown 0.10, bookdown 0.9.1, brew 1.0-6, broom 0.5.1, cellranger 1.1.0, cli 1.0.1, colorspace 1.3-2, crayon 1.3.4, crosstalk 1.0.0, data.table 1.11.8, DiagrammeR 1.0.0, digest 0.6.18, downloader 0.4, dplyr 0.8.0.9000, evaluate 0.12, forcats 0.3.0, generics 0.0.2, ggdendro 0.1-20, ggformula 0.9.1, ggplot2 3.1.0, ggrepel 0.8.0, ggstance 0.3.1, glue 1.3.0.9000, gridExtra 2.3, gtable 0.2.0, haven 2.0.0, hms 0.4.2, htmltools 0.3.6, htmlwidgets 1.3, httpuv 1.4.5.1, httr 1.4.0, igraph 1.2.2, influenceR 0.1.0, jsonlite 1.6, knitr 1.21, later 0.7.5, lattice 0.20-35, lazyeval 0.2.1, leaflet 2.0.2, lubridate 1.7.4, magrittr 1.5, MASS 7.3-50, Matrix 1.2-14, mime 0.6, modelr 0.1.2, mosaic 1.5.0, mosaicCore 0.6.0, mosaicData 0.17.0, munsell 0.5.0, nlme 3.1-137, pillar 1.3.1, pkgconfig 2.0.2, plotly 4.8.0, plyr 1.8.4, promises 1.0.1, purrr 0.2.5, R6 2.3.0, RColorBrewer 1.1-2, Rcpp 1.0.0, readr 1.3.1, readxl 1.2.0, rgexf 0.15.3, rlang 0.3.1, rmarkdown 1.11.3, Rook 1.1-1, rstudioapi 0.9.0, rvest 0.3.2, scales 1.0.0, sessioninfo 1.1.1.9000, shiny 1.2.0, stringi 1.2.4, stringr 1.3.1, tibble 2.0.0, tidyr 0.8.2, tidyselect 0.2.5, tidyverse 1.2.1, viridis 0.5.1, viridisLite 0.3.0, visNetwork 2.0.5, withr 2.1.2, xfun 0.4, XML 3.98-1.16, xml2 1.2.0, xtable 1.8-3, yaml 2.2.0

An example clean session info page (p. 70), from a recent rmarkdown presention looks like this: