Skip to content

Instantly share code, notes, and snippets.

@bgall
Created December 1, 2019 20:29
Show Gist options
  • Save bgall/23817e228803798eafc9346dff0c1714 to your computer and use it in GitHub Desktop.
Save bgall/23817e228803798eafc9346dff0c1714 to your computer and use it in GitHub Desktop.
Load packages for simulation-based power calculation
#########################################################################
# 'loadpkg' function
# Checks if a vector of packages are installed. If not, installs the
# package. Then loads all packages in vector.
#########################################################################
loadpkg <- function(toLoad){
for(lib in toLoad){
if(! lib %in% installed.packages()[,1]) {
install.packages(lib, repos='http://cran.rstudio.com/')
}
suppressMessages( library(lib, character.only=TRUE) )
}
}
# Load dependencies
pkgs <- c("dplyr", # for data processing and pipe operators
"estimatr", # for fast lm() with clustered SEs
"ggplot2", # for visualizing power
)
loadpkg(pkgs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment