#' Pretty session info
#'
#' Wraps the session information output chunk in a collapsible HTML element
#' so that it doesn't dominate the compiled chapter.
#'
#' @author Aaron Lun
#'
#' @return Prints a HTML block containing a collapsible section with session information.
#'
#' @seealso
#' \code{\link{setupHTML}} and \code{\link{chapterPreamble}}, to set up the code for the collapsible element.
#'
#' @export
#' @examples
#' tmp <- tempfile(fileext=".Rmd")
#' write(file=tmp, "```{r, echo=FALSE, results='asis'}
#' rebook::setupHTML()
#' ```
#'
#' ```{r, results='asis'}
#' prettySessionInfo()
#' ```")
#'
#' rmarkdown::render(tmp)
#'
#' if (interactive()) browseURL(sub(".Rmd$", ".html", tmp))
#'
#' @importFrom utils capture.output sessionInfo
prettySessionInfo <- function() {
## grab session info printed output
X <- capture.output(sessionInfo())
## print session info out into collapsible div
cat('<button class="rebook-collapse">View session info</button>
<div class="rebook-content">\n')
cat(c("```", X, "```"), sep="\n")
cat("</div>\n")
invisible(NULL)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.