Skip to content

Instantly share code, notes, and snippets.

View pbaylis's full-sized avatar

Patrick Baylis pbaylis

View GitHub Profile
@pbaylis
pbaylis / rstudio-reset.sh
Last active December 29, 2020 18:56
RStudio Server reset
rm -rf ~/.rstudio
rstudio-server kill-all
@pbaylis
pbaylis / reduce-merge.R
Created July 4, 2020 21:16
Reduce merge
Reduce(function(x, y) merge(x, y, all=TRUE), list(df1, df2, df3))
# OR #
Reduce(function(...) merge(..., all=TRUE), list(df1, df2, df3))
@pbaylis
pbaylis / sensitivity-curve.R
Last active July 12, 2020 02:06
Plot a sensitivity curve
# Create sensitivity curve of coefficient estimates
library(tidyverse)
library(cowplot)
library(fastDummies)
# Setup ----
rm(list = ls())
theme_set(theme_cowplot())
set.seed(42)
@pbaylis
pbaylis / dynamic-var-names-dplyr.R
Created May 27, 2019 18:35
Dynamic variable names with dplyr
multipetal <- function(df, n) {
varname <- paste("petal", n , sep=".")
mutate(df, !!varname := Petal.Width * n)
}
@pbaylis
pbaylis / points-in-polys.R
Created May 27, 2019 18:33
Points in polygons with sf
points.shp <- points.shp[apply(sf::st_intersects(points.shp, polys), 1, any),]
@pbaylis
pbaylis / mult-fxn-mult-col.R
Created May 27, 2019 18:31
Apply multiple functions to multiple columns (with data.table)
my.summary = function(x) list(mean = mean(x), median = median(x))
DT[, as.list(unlist(lapply(.SD, my.summary))), .SDcols = c('a', 'b')]
@pbaylis
pbaylis / pad-with-zeroes.R
Created May 27, 2019 18:30
Pad integers with zeroes
x <- c(5, 15, 2015)
sprintf(sprintf("%03d", x))
@pbaylis
pbaylis / execute-tmux.sh
Last active May 16, 2019 15:35
Use tmux to run commands through ssh (that won't close when you log out)
## Logging into server
ssh <server-address>
# Login
tmux
# CTRL-b d to detach tmux
exit
## When returning to server
tmux attach
@pbaylis
pbaylis / update-beamer-packages.R
Created May 16, 2019 15:11
Install missing style files (R, tinytex)
library(tinytex)
tlmgr_search('/times.sty') # search for times.sty
tlmgr_install('psnfss') # install the psnfss package
tlmgr_update() # update everything
@pbaylis
pbaylis / bear_morning.sh
Created March 31, 2017 06:56
Shell script to open Bear with a daily log template
#!/bin/bash
DATE=`date "+%A, %b %d %Y"`
YESTERDAY=`date -v-1d "+%A, %b %d %Y"`
open "bear://x-callback-url/create?title=$DATE&text=## Beginning of day thoughts
## Goals
-
## End of day thoughts
[[$YESTERDAY]]&tags=dailylog"