Run a knitr hook at the end of the document

I would like to place a hook in index.Rmd of my bookdown book and have it execute at the end of the knitting process.

# I tried
knitr::opts_hooks$set(document = {
  session_info <- devtools::session_info()
  save(session_info, file = "session_info.RData")
})

This code creates session_info at the beginning of the knitting process, not at the end after all packages have been loaded and attached.

I tried using a full-fledged function but this did not create the session_info object.

knitr::opts_hooks$set(document = function (x) {
  session_info <- devtools::session_info()
  save(session_info, file = "session_info.RData")
  base::identity(x)
})

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