Skip to content

Instantly share code, notes, and snippets.

@benjamin-chan
benjamin-chan / markdown.css
Last active November 24, 2015 23:41
CHSE CSS for RMarkdown
body, td {
font-family: 'Lato', sans-serif;
background-color: white;
font-size: medium;
margin: 8px;
}
tt, code, pre {
font-family: Consolas, Monaco, monospace;
}
@benjamin-chan
benjamin-chan / R.nanorc
Last active April 27, 2025 14:56
R syntax highlighting for nano editor
################################################################################
#
# R.nanorc -- nano syntax-highlighting file for R
#
# Origin: This file is part of the pkgutils package for R.
#
# Usage: This file should be placed in a directory such as /usr/share/nano/ (on
# Ubuntu 12.04). That nano uses syntax highlighting at all might need to be
# enabled separately.
@benjamin-chan
benjamin-chan / roll_ipython_in_aws.md
Created May 28, 2016 09:23 — forked from iamatypeofwalrus/roll_ipython_in_aws.md
Create an iPython HTML Notebook on Amazon's AWS Free Tier from scratch.

What

Roll your own iPython Notebook server with Amazon Web Services (EC2) using their Free Tier.

What are we using? What do you need?

  • An active AWS account. First time sign-ups are eligible for the free tier for a year
  • One Micro Tier EC2 Instance
  • With AWS we will use the stock Ubuntu Server AMI and customize it.
  • Anaconda for Python.
  • Coffee/Beer/Time
@benjamin-chan
benjamin-chan / create-R-EC2.sh
Last active May 28, 2016 13:09 — forked from randyzwitch/create-R-EC2.sh
Using R on Amazon EC2 - Part 1
#Create a user, home directory and set password
sudo useradd rstudio
sudo mkdir /home/rstudio
sudo passwd rstudio
sudo chmod -R 0777 /home/rstudio
#Update all files from the default state
sudo apt-get update
sudo apt-get upgrade
@benjamin-chan
benjamin-chan / r-ec2-part2.sh
Created May 28, 2016 13:09 — forked from randyzwitch/r-ec2-part2.sh
Using R on Amazon EC2 - Part 2
#Install in order to use RCurl & XML
sudo aptitude install libcurl4-openssl-dev
sudo apt-get install libxml2-dev
@benjamin-chan
benjamin-chan / header.R
Last active June 3, 2016 15:53
Script to run before R session
checkPackage <- function (pkg) {
# Check if pkg is installed; if not then install it; if an update exists then update
# Usage:
# > checkPackage("data.table")
if (is.character(pkg) == TRUE) {
repos <- "https://cloud.r-project.org"
if(pkg %in% rownames(installed.packages()) == FALSE) {
install.packages(pkg, repos=repos, dependencies=TRUE)
rowid <- which(installed.packages()[, "Package"] == pkg)
pkgInfo <- installed.packages()[rowid, ]
@benjamin-chan
benjamin-chan / install_prepR.R
Created June 8, 2016 18:33
Install the prepR package
install.packages("devtools")
library("devtools")
devtools::install_github("klutometis/roxygen")
library(roxygen2)
setwd("C:/Users/chanb/Documents/GitHub Repositories")
create("prepR")
setwd("./prepR")
document()
@benjamin-chan
benjamin-chan / installPackages.R
Last active September 14, 2016 17:14
Install R packages in bulk
packages <- c("devtools",
"data.table",
"lubridate",
"ggplot2",
"haven",
"readxl",
"tidyr",
"lme4",
"metafor",
"DiagrammeR",
@benjamin-chan
benjamin-chan / getSynPUF.R
Last active July 29, 2016 21:25
Download CMS 2008-2010 Data Entrepreneurs' Synthetic Public Use File (DE-SynPUF)
getSynPUF <- function (zipFile) {
# [CMS 2008-2010 Data Entrepreneurs' Synthetic Public Use File (DE-SynPUF)](https://www.cms.gov/Research-Statistics-Data-and-Systems/Downloadable-Public-Use-Files/SynPUFs/DE_Syn_PUF.html)
#
# Examples:
#
# > getSynPUF("DE1_0_2008_to_2010_Carrier_Claims_Sample_1A.zip")
# > getSynPUF("DE1_0_2008_to_2010_Carrier_Claims_Sample_1B.zip")
# > getSynPUF("DE1_0_2010_Beneficiary_Summary_File_Sample_1.zip")
#
require(readr)
@benjamin-chan
benjamin-chan / installMarkDoc.do
Last active August 11, 2016 18:02
Set up and install MarkDoc for Stata
/* See http://www.haghish.com/statistics/stata-blog/reproducible-research/markdoc.php */
ssc install markdoc /* installing MarkDoc package */
ssc install weaver /* installing Weaver package */
ssc install statax /* installing Statax package */
markdoc smclfile, replace install export(docx) /* exporting Microsoft Office Docx word */
markdoc adofile, replace install export(sthlp)/* exporting sthlp Stata help file */