This R package provides a single function, durnit
, which takes an
input and an output directory as arguments. All Rmd files in the input
directory (or its subdirectories) are knitted to the output directory
using rmarkdown::render
and the output format specified in each file’s
YAML frontmatter. On subsequent runs only new or modified Rmd files are
knitted.
Install the development (and only) version from GitHub:
remotes::install_github(davidsbutcher/durnit)
The package contains a single function, durnit
, whose name is intended
to evoke the phrase “directory knit”. It accepts two arguments, which
specify the directory to search for Rmd files and the directory to save
output to:
durnit(input_dir, output_dir)
All Rmd files in the input directory are rendered to the output
directory using rmarkdown::render
with the output format taken from
the YAML frontmatter. Directory structure in the input directory is
maintained, e.g. inputdir/notebook/June-2019/lcms.Rmd
will be saved to
outputdir/notebook/June-2019/lcms.html
.
The output directory is also checked for a file called rmdsnapshot.rds
containing information (time of last modification, MD5 sum, etc.) on any
Rmd files already knitted using durnit
. If it doesn’t exist, it is
created. If it does exist, a new snapshot is compared to the existing
one and only new or modified Rmd files are knitted. The new snapshot
replaces the existing one.
This function was originally designed to assist in the keeping of an
electronic lab notebook as a collection of Rmd files, but could be
useful for any collection of Rmd files which need to knitted without
doing them one at a time. It is also optimized to allow it to be run
regularly (e.g. using taskscheduleR
) to keep the output documents
up-to-date.
If you want the output document to contain the time it was last knitted,
you can use the following code, which requires rprojroot
:
format(file.info(rprojroot::thisfile_knit())$mtime, '%B %d, %Y')
## [1] "October 08, 2019"
furrr
functionsThis package imports functions from purrr
, magrittr
, rmarkdown
,
and fs
.
Creative Commons CC0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.