Skip to content

Instantly share code, notes, and snippets.

View eipi10's full-sized avatar

Joel Schwartz eipi10

  • California State University, Sacramento
View GitHub Profile
@bschneidr
bschneidr / extract_plots_from_list.R
Created April 17, 2019 21:06
Extract all of the ggplot2 plots from a list (including sub-lists)
#' @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)
#'
@mbjoseph
mbjoseph / zoib-recovery.R
Created November 27, 2017 07:33
Simulation for zero-one inflated beta regression in Stan
## DATA GENERATION
# reproducibility
library(bayesplot)
set.seed(1839)
# matches the stan function
inv_logit <- function(x){
exp(x) / (1 + exp(x))
}
@plpxsk
plpxsk / cancer-analysis.md
Last active July 27, 2021 17:26
Example project

An example analysis, which follows my project template.

Some data redacted.

Makefile

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)
}