diff --git a/R/runAllChunks.R b/R/runAllChunks.R new file mode 100644 index 0000000000000000000000000000000000000000..cc7ff57f028f42cfeddd4b718f60ab2b7d9e84fe --- /dev/null +++ b/R/runAllChunks.R @@ -0,0 +1,34 @@ +#' @title Run all chunks in a Rmd file +#' +#' @name runAllChunks +#' +#' @description This function was developed to run all chunks in a knitr +#' Rmd (R markdown) file at once. Mainly for exploring and debugging +#' purposes. +#' +#' @param Rmd the name of the Rmd file. +#' +#' @param envir the environment in which the chunks will be +#' evaluated. By default it is the GlobalEnv. +#' +#' @references This function was based on this +#' \href{http://stackoverflow.com/questions/24753969/knitr-run-all-chunks-in-an-rmarkdown-document}{SO +#' thread}. +#' +#' @return Objects created in the chunks from the Rmd file. +#' +#' @import knitr +#' +#' @author Fernando Mayer, \email{fernando.mayer@@ufpr.br} +#' +#' @export +runAllChunks <- function(Rmd, envir = globalenv()){ + if (!requireNamespace("knitr", quietly = TRUE)){ + stop("`knitr` needed for this function to work. Please install it.", + call. = FALSE) + } + tempR <- tempfile(tmpdir = ".", fileext = ".R") + on.exit(unlink(tempR)) + purl(Rmd, output = tempR) + sys.source(tempR, envir = envir) +} diff --git a/man/runAllChunks.Rd b/man/runAllChunks.Rd new file mode 100644 index 0000000000000000000000000000000000000000..3602646e0ca20153358dd7f3bf75304c4902a54f --- /dev/null +++ b/man/runAllChunks.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/runAllChunks.R +\name{runAllChunks} +\alias{runAllChunks} +\title{Run all chunks in a Rmd file} +\usage{ +runAllChunks(Rmd, envir = globalenv()) +} +\arguments{ +\item{Rmd}{the name of the Rmd file.} + +\item{envir}{the environment in which the chunks will be +evaluated. By default it is the GlobalEnv.} +} +\value{ +Objects created in the chunks from the Rmd file. +} +\description{ +This function was developed to run all chunks in a knitr +Rmd (R markdown) file at once. Mainly for exploring and debugging +purposes. +} +\author{ +Fernando Mayer, \email{fernando.mayer@ufpr.br} +} +\references{ +This function was based on this + \href{http://stackoverflow.com/questions/24753969/knitr-run-all-chunks-in-an-rmarkdown-document}{SO + thread}. +} +