Skip to content

Instantly share code, notes, and snippets.

View gu-mi's full-sized avatar

Gu Mi gu-mi

  • Sanofi
  • Cambridge, MA
View GitHub Profile
@gu-mi
gu-mi / color_scheme.sh
Created May 24, 2014 21:00
TeXShop color scheme
# solarized light color scheme for my TexShop setup
defaults write TeXShop background_R 0.99
defaults write TeXShop background_G 0.96
defaults write TeXShop background_B 0.89
defaults write TeXShop commandred 0.0
defaults write TeXShop commandgreen 0.0
defaults write TeXShop commandblue 1.0
@gu-mi
gu-mi / install_load_pkgs.R
Created May 19, 2014 02:03
Detect which packages are not installed, and then install them and load all required packages into session.
# check if you need to install these packages
pkg <- c("RODBC", "ggplot2")
inst <- pkg %in% installed.packages()
# inst
if (length(pkg[!inst]) > 0) {
install.packages(pkg[!inst])
}
# load all required packages into session
lapply(pkg, library, character.only = TRUE)
@gu-mi
gu-mi / replace.R
Created May 12, 2014 15:34
replace @S3method with @export
# http://trinkerrstuff.wordpress.com/2014/05/12/handling-s3methods-death-in-roxygen-4-0-0/
pth <- "C:/Users/trinker/qdap/R"
fls <- file.path(pth, dir(pth))
FUN <- function(x) {
cont <- readLines(x)
cont[grepl("#' @S3", cont)] <- "#' @export"
cont[length(cont) + 1] <- ""
## Add an alpha value to a colour
add.alpha <- function(col, alpha=1){
if(missing(col))
stop("Please provide a vector of colours.")
apply(sapply(col, col2rgb)/255, 2,
function(x)
rgb(x[1], x[2], x[3], alpha=alpha))
}
@gu-mi
gu-mi / update_R_pkgs.R
Last active December 15, 2015 20:48
On a Mac OS, re-install R packages installed for R 2.15.X, when upgrading to R 3.0.0
# http://randyzwitch.com/automated-re-install-of-packages-for-r-3-0/
# if using RStudio, make sure to unload all packages that are pre-loaded except for utils:
# we have to use the install.packages() function in utils for the re-installation
# Get currently installed packages
package_df <- as.data.frame(installed.packages("/Library/Frameworks/R.framework/Versions/2.15/Resources/library"))
package_list <- as.character(package_df$Package)
package_list # get a package list installed on R 2.15.X
length(package_list)
@gu-mi
gu-mi / global.R
Created March 21, 2013 06:14 — forked from pssguy/global.R
# load required libraries
library(shiny)
library(plyr)
library(ggplot2)
library(googleVis)
library(reshape2)
####creation of example data on local directory for uploading####
@gu-mi
gu-mi / installation of Cufflinks
Last active December 14, 2015 07:59
Instructions for installing Cufflinks and related tools in Mac OS X
library(randomForest)
# download Titanic Survivors data
data <- read.table("http://math.ucdenver.edu/RTutorial/titanic.txt", h=T, sep="\t")
# make survived into a yes/no
data$Survived <- as.factor(ifelse(data$Survived==1, "yes", "no"))
# split into a training and test set
idx <- runif(nrow(data)) <= .75
data.train <- data[idx,]
library(stringr)
names(iris)
#[1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species"
names(iris) <- str_replace_all(names(iris), "[.]", "_")
names(iris)
#[1] "Sepal_Length" "Sepal_Width" "Petal_Length" "Petal_Width" "Species"
s <- c("Go to Heaven for the climate, Hell for the company.")
str_extract_all(s, "[H][a-z]+ ")
library(sqldf)
sqldf("SELECT
day
, avg(temp) as avg_temp
FROM beaver2
GROUP BY
day;")
# day avg_temp