An example analysis, which follows my project template.
Some data redacted.
makefile controls all code (except the Rmd notebooks)
all: clean data process pool
#' @title Extract ggplot2 plots from a list | |
#' @description Takes a list (potentially containing sublists) and extracts all of the ggplot2 'plot-type' objects from that list into a simple list of 'plot-type' objects. | |
#' @param x A list object, potentially containing sublists. | |
#' @return Returns a 'flat', single-level list of all the ggplot2 'plot-type' objects from within `x`, reaching recursively into sub-lists as needed. If there are no 'plot-type' objects, returns an empty list. | |
#' @note Whether an object is a ggplot2 'plot-type' object is defined here as an object with classes 'gg', 'gTree', or 'gtable'. | |
#' @export | |
#' @examples | |
#' | |
#' library(ggplot2) | |
#' |
## DATA GENERATION | |
# reproducibility | |
library(bayesplot) | |
set.seed(1839) | |
# matches the stan function | |
inv_logit <- function(x){ | |
exp(x) / (1 + exp(x)) | |
} |
An example analysis, which follows my project template.
Some data redacted.
makefile controls all code (except the Rmd notebooks)
all: clean data process pool
This is a short demo of how to use brew
and knitr
in combination with each other to get the best of the templating facilities in brew
and the literate programming functions in knitr
. The main idea is to write a function brew_knit
# Preprocess template using brew and then run knit on the output
brew_knit <- function(template, params, ...){
brew::brew(template, envir = list2env(params))
input = gsub(".Rnwe", '.Rnw', template)
knitr::knit(input)
}