This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rename image files using YYYYMMDD_HHMMSS in local time | |
# assumes your working directory is where the image files are | |
library("dplyr") | |
library("exifr") | |
library("lubridate") | |
filetype <- "HEIC" | |
old_names <- list.files(pattern = paste0("*.", filetype)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("drake") | |
files = list.files("data", "*.csv", full.names = TRUE) | |
add2 = function(d) { # example function to apply to each individual data.frame | |
d$x = d$x+2 | |
return(d) | |
} | |
plan = drake_plan( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{beamer} | |
\usetheme{AnnArbor} | |
\usecolortheme{beaver} | |
\usefonttheme[onlymath]{serif} % uncomment for article style math | |
\setlength{\unitlength}{\textwidth} % measure in textwidths | |
\usepackage[normalem]{ulem} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From https://gist.github.com/jarad/8f3b79b33489828ab8244e82a4a0c5b3 | |
library("dplyr") | |
library("tidyr") | |
library("readr") | |
read_my_csv = function(f, into) { | |
readr::read_csv(f) %>% | |
dplyr::mutate(file = f) %>% | |
tidyr::separate(file, into) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
y = rnorm(5) | |
log_like = function(theta, y) { | |
sum(dnorm(y,theta,log=TRUE)) | |
} | |
thetas = c(1,2) | |
# Evaluating the theta vector one at a time works, | |
log_like(thetas[1],y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From http://stackoverflow.com/questions/4090169/elegant-way-to-check-for-missing-packages-and-install-them | |
install_and_load_packages <- function(x){ | |
for( i in x ){ | |
# require returns TRUE invisibly if it was able to load package | |
if( ! require( i , character.only = TRUE ) ){ | |
# If package was not able to be loaded then re-install | |
install.packages( i , dependencies = TRUE ) | |
# Load package after installing | |
require( i , character.only = TRUE ) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mn = 3 | |
f = function(x) { | |
n = length(x) | |
apply(.5*cbind(dnorm(x,-mn),dnorm(x,mn)),1,sum) | |
} | |
# Random-walk Metropolis | |
set.seed(1) | |
n.reps = 1e5 | |
x.reps = rep(NA,n.reps) |