squeeze_rmds: A Simple Wrapper for Tangling Code in Bookdown Projects

View source: R/squeeze_Rmds.R

squeeze_rmdsR Documentation

A Simple Wrapper for Tangling Code in Bookdown Projects

Description

This function extracts R code from .Rmd files belonging to bookdown projects. By default, it scans the working directory for numbered .Rmd files and passes them to knitr::purl() which tangles the code chunks whithin to .R files. It is intended as a convenience function for students working with Introduction to Econometrics with R, an interactive online-companion to the textbook Introduction to Econometrics (Stock & Watson 2015). The companion can be found here. The function works with arbitrary .Rmd files and is useful for working with other bookdown projects, too.

Usage

squeeze_rmds(dir = ".", numbered = T, out = "Rcodes", prefix = "", ...)

Arguments

dir

Path of the directory containing the .Rmd files to be tangled. Default is the current working directory.

numbered

logical. If TRUE, only numbers in the original file names are retained.

out

Path to the output directory where the tangled codes will be saved. Points the ./Rcode by default.

prefix

character. A prefix to be added to the .R file names.

...

Further arguments passed to knitr::purl().

Examples

## Not run: 
# tangle numbered chapters of a bookdown project at working directory
squeeze_rmds(numbered = TRUE, prefix = "Chapter_")

## End(Not run)

mca91/itewrpkg documentation built on Nov. 10, 2023, 12:03 p.m.