Skip to content

Instantly share code, notes, and snippets.

@brshallo
brshallo / source_rmd.R
Last active April 1, 2021 07:10 — forked from noamross/source_rmd.R
Source an RMD file
#' Source the R code from an knitr file, optionally skipping plots
#'
#' @param file the knitr file to source
#' @param skip_plots whether to make plots. If TRUE (default) sets a null graphics device
#'
#' @return This function is called for its side effects
#' @export
source_rmd = function(file, skip_plots = TRUE) {
temp = tempfile(fileext=".R")
knitr::purl(file, output=temp)