R/prettySessionInfo.R

Defines functions prettySessionInfo

Documented in prettySessionInfo

#' 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)
}

Try the rebook package in your browser

Any scripts or data that you put into this service are public.

rebook documentation built on Nov. 8, 2020, 4:56 p.m.