Skip to content

Instantly share code, notes, and snippets.

View sjessa's full-sized avatar

Selin Jessa sjessa

View GitHub Profile
@sjessa
sjessa / knit.sh
Created July 6, 2018 20:10
knit Rmd from commandline
# save in .bashrc
# usage: knit 01-analysis.Rmd
function knit() {
R --no-save -e "rmarkdown::render('""$1""', 'html_document')"
}
@sjessa
sjessa / prompt.sh
Last active July 6, 2018 20:01
simple bash prompt
# to add to ~/.bashrc
# e.g. selinjessa @ iMacPro @ ~ # 22846.test $
export PS1="\[\e[34m\]\u \[\e[m\]@ \[\e[31m\]\h \[\e[m\]@ \[\e[36m\]\W \[\e[m\]# ${STY} $ "
@sjessa
sjessa / tidyeval_filter.R
Last active July 6, 2018 20:09
Filter a data frame based on a set of expressions
# Filters
library(tidyverse)
sample_filters <- quos(project %in% c("dev", species %in% c("mouse")))
sample_list <- data.frame(
project = c("dev", "pbt"),
species = c("mouse", "human"),
dont_filter = c("a", "b"))
@sjessa
sjessa / setup
Last active June 28, 2017 18:17
My preferred knitr chunk settings for R Markdown documents
```{r setup, echo = FALSE, message = FALSE, warning = FALSE}
knitr::opts_chunk$set(dev = "pdf", # Save figures as PDFs
fig.keep = "all",
fig.path = "figures/", # Figures are saved to this directory
message = FALSE, # Hide messages/warnings/errors from loading packages
warning = FALSE,
error = FALSE,
cache = TRUE) # By default, cache results to avoid re-running
# super long things every time you knit
@sjessa
sjessa / knitsnapshot.sh
Created May 1, 2017 14:18
Knit an R Markdown document from the commandline, and specify the output filename
R -e 'library(knitr); knit("report.Rmd", "report.md")'; pandoc report.md --output snapshot.pdf --variable 'geometry:margin=1in'
@sjessa
sjessa / selinj.zsh-theme
Created September 27, 2016 16:36
My zsh theme
PROMPT=" %{$fg[magenta]%}%n%{$reset_color%} @ %{$fg[yellow]%}%m%{$reset_color%} in %{$fg[green]%}%c%{$reset_color%} # %{$fg[blue]%}\${STY}%{$reset_color%} # %{$fg[blue]%}\$(git_prompt_info)%{$fg[blue]%} % %{$reset_color%}
%{$fg[blue]%}➜ %{$reset_color%} "
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%} %{$fg[green]%}✗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%}"
@sjessa
sjessa / dynamicsource.R
Created July 13, 2016 17:48
dynamically source a file in R
# Source a file in the same directory as the script regardless of the
# working directory from which the script is being called.
# Works in conjunction with argparser.
# Adapted from http://stackoverflow.com/a/1815743
command <- commandArgs(trailingOnly = FALSE)
script_name <- sub("--file=", "", command[grep("--file=", command)])
script_path <- dirname(script_name)
my_functions <- file.path(script_path, "functions.R")
source(my_functions, chdir = TRUE)
@sjessa
sjessa / lmake.sh
Last active July 13, 2016 00:52
log your make commands & output
# Usage: $ lmake <make options here> <optional make target>
function lmake ()
{
echo "Appending make command output to make.log"
echo "Running command..."
echo "" >>make.log
echo "------------------------------------------" >>make.log
echo " MAKE LAUNCHED" >>make.log