Best practices for saving session information

In the spirit of improving the reproducibility of my workflow, I'm trying to figure out the best way to save session information for reports or bookdown books in which it is not desirable to include the session info in the final project.

A few considerations:

  1. I would like to save the session information in human readable format. Since both sessionInfo() and devtools::session_info() output lists, it's not obvious how to save or nicely display this information. For saving, the best option I've found is to use capture.output() per this SO answer. For printing, changing the options() width setting is the only thing I've found to make the package list look nice. Seems like a prime candidate for a tidy() method...

  2. Would best practices be affected by the output type: whether I'm running an R script, knitting an .Rmd file to html_document, or creating a bookdown book?

  3. Would best practices be affected by whether I'm, say, rendering a bookdown book locally vs. by Travis?

  4. How should rmarkdown caching be handled? Does the installation of new packages break the cache? If not, which I'm guessing is the case, then the session info is not accurate for cached chunks.

Thanks for all your thoughts on the broad topic.

1 Like

I haven't seen enough on this topic to suggest a best practice. I have a few suggestions.

  1. You can create a session object, such as
demo.Rmd_session_2019_11_15 <- sessionInfo()
  1. Obviously this works best with version control, such as git.

  2. You can format following the reprex below

library(pander)
library(sessioninfo)
demo.Rmd_session_2019_11_15 <- session_info()
pander(demo.Rmd_session_2019_11_15)
#> Warning in pander.default(demo.Rmd_session_2019_11_15): No pander.method for
#> "session_info", reverting to default.
#> Warning in pander.default(x[[i]], indent = indent + 1): No pander.method for
#> "platform_info", reverting to default.
  • platform:

    • version: R version 3.6.1 (2019-07-05)
    • os: macOS Mojave 10.14.6
    • system: x86_64, darwin15.6.0
    • ui: X11
    • language: (EN)
    • collate: en_US.UTF-8
    • ctype: en_US.UTF-8
    • tz: America/Los_Angeles
    • date: 2019-11-15
  • packages:

    Table continues below
    package ondiskversion loadedversion
    assertthat assertthat 0.2.1 0.2.1
    cli cli 1.1.0 1.1.0
    crayon crayon 1.3.4 1.3.4
    digest digest 0.6.22 0.6.22
    evaluate evaluate 0.14 0.14
    highr highr 0.8 0.8
    htmltools htmltools 0.4.0 0.4.0
    knitr knitr 1.26 1.26
    magrittr magrittr 1.5 1.5
    pander pander 0.6.3 0.6.3
    Rcpp Rcpp 1.0.3 1.0.3
    rlang rlang 0.4.1 0.4.1
    rmarkdown rmarkdown 1.17 1.17
    sessioninfo sessioninfo 1.1.1 1.1.1
    stringi stringi 1.4.3 1.4.3
    stringr stringr 1.4.0 1.4.0
    withr withr 2.1.2 2.1.2
    xfun xfun 0.11 0.11
    yaml yaml 2.2.0 2.2.0
    Table continues below
    path
    assertthat /Users/rc/Library/R/3.6/library/assertthat
    cli /Users/rc/Library/R/3.6/library/cli
    crayon /Users/rc/Library/R/3.6/library/crayon
    digest /Users/rc/Library/R/3.6/library/digest
    evaluate /Users/rc/Library/R/3.6/library/evaluate
    highr /Users/rc/Library/R/3.6/library/highr
    htmltools /Users/rc/Library/R/3.6/library/htmltools
    knitr /Users/rc/Library/R/3.6/library/knitr
    magrittr /Users/rc/Library/R/3.6/library/magrittr
    pander /Library/Frameworks/R.framework/Versions/3.6/Resources/library/pander
    Rcpp /Users/rc/Library/R/3.6/library/Rcpp
    rlang /Users/rc/Library/R/3.6/library/rlang
    rmarkdown /Users/rc/Library/R/3.6/library/rmarkdown
    sessioninfo /Users/rc/Library/R/3.6/library/sessioninfo
    stringi /Users/rc/Library/R/3.6/library/stringi
    stringr /Users/rc/Library/R/3.6/library/stringr
    withr /Users/rc/Library/R/3.6/library/withr
    xfun /Users/rc/Library/R/3.6/library/xfun
    yaml /Users/rc/Library/R/3.6/library/yaml
    Table continues below
    loadedpath
    assertthat /Users/rc/Library/R/3.6/library/assertthat
    cli /Users/rc/Library/R/3.6/library/cli
    crayon /Users/rc/Library/R/3.6/library/crayon
    digest /Users/rc/Library/R/3.6/library/digest
    evaluate /Users/rc/Library/R/3.6/library/evaluate
    highr /Users/rc/Library/R/3.6/library/highr
    htmltools /Users/rc/Library/R/3.6/library/htmltools
    knitr /Users/rc/Library/R/3.6/library/knitr
    magrittr /Users/rc/Library/R/3.6/library/magrittr
    pander /Library/Frameworks/R.framework/Versions/3.6/Resources/library/pander
    Rcpp /Users/rc/Library/R/3.6/library/Rcpp
    rlang /Users/rc/Library/R/3.6/library/rlang
    rmarkdown /Users/rc/Library/R/3.6/library/rmarkdown
    sessioninfo /Users/rc/Library/R/3.6/library/sessioninfo
    stringi /Users/rc/Library/R/3.6/library/stringi
    stringr /Users/rc/Library/R/3.6/library/stringr
    withr /Users/rc/Library/R/3.6/library/withr
    xfun /Users/rc/Library/R/3.6/library/xfun
    yaml /Users/rc/Library/R/3.6/library/yaml
    Table continues below
    attached is_base date source md5ok
    assertthat FALSE FALSE 2019-03-21 CRAN (R 3.6.0) NA
    cli FALSE FALSE 2019-03-19 CRAN (R 3.6.0) NA
    crayon FALSE FALSE 2017-09-16 CRAN (R 3.6.0) NA
    digest FALSE FALSE 2019-10-21 CRAN (R 3.6.1) NA
    evaluate FALSE FALSE 2019-05-28 CRAN (R 3.6.0) NA
    highr FALSE FALSE 2019-03-20 CRAN (R 3.6.0) NA
    htmltools FALSE FALSE 2019-10-04 CRAN (R 3.6.0) NA
    knitr FALSE FALSE 2019-11-12 CRAN (R 3.6.1) NA
    magrittr FALSE FALSE 2014-11-22 CRAN (R 3.6.0) NA
    pander TRUE FALSE 2018-11-06 CRAN (R 3.6.0) NA
    Rcpp FALSE FALSE 2019-11-08 CRAN (R 3.6.1) NA
    rlang FALSE FALSE 2019-10-24 CRAN (R 3.6.1) NA
    rmarkdown FALSE FALSE 2019-11-13 CRAN (R 3.6.1) NA
    sessioninfo TRUE FALSE 2018-11-05 CRAN (R 3.6.0) NA
    stringi FALSE FALSE 2019-03-12 CRAN (R 3.6.0) NA
    stringr FALSE FALSE 2019-02-10 CRAN (R 3.6.0) NA
    withr FALSE FALSE 2018-03-15 CRAN (R 3.6.0) NA
    xfun FALSE FALSE 2019-11-12 CRAN (R 3.6.1) NA
    yaml FALSE FALSE 2018-07-25 CRAN (R 3.6.0) NA
    library
    assertthat /Users/rc/Library/R/3.6/library
    cli /Users/rc/Library/R/3.6/library
    crayon /Users/rc/Library/R/3.6/library
    digest /Users/rc/Library/R/3.6/library
    evaluate /Users/rc/Library/R/3.6/library
    highr /Users/rc/Library/R/3.6/library
    htmltools /Users/rc/Library/R/3.6/library
    knitr /Users/rc/Library/R/3.6/library
    magrittr /Users/rc/Library/R/3.6/library
    pander /Library/Frameworks/R.framework/Versions/3.6/Resources/library
    Rcpp /Users/rc/Library/R/3.6/library
    rlang /Users/rc/Library/R/3.6/library
    rmarkdown /Users/rc/Library/R/3.6/library
    sessioninfo /Users/rc/Library/R/3.6/library
    stringi /Users/rc/Library/R/3.6/library
    stringr /Users/rc/Library/R/3.6/library
    withr /Users/rc/Library/R/3.6/library
    xfun /Users/rc/Library/R/3.6/library
    yaml /Users/rc/Library/R/3.6/library

Created on 2019-11-15 by the reprex package (v0.3.0)

1 Like

Looks great, thanks!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.