Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrie de Vries andrie

View GitHub Profile
@andrie
andrie / cleanGoogleTable.R
Last active Nov 20, 2016
Functions to read Google Docs spreadsheet into R
View cleanGoogleTable.R
library(XML)
cleanGoogleTable <- function(dat, table=1, skip=0, ncols=NA, nrows=-1, header=TRUE, dropFirstCol=NA){
if(!is.data.frame(dat)){
dat <- dat[[table]]
}
if(is.na(dropFirstCol)) {
firstCol <- na.omit(dat[[1]])
if(all(firstCol == ".") || all(firstCol== as.character(seq_along(firstCol)))) {
dat <- dat[, -1]
}
View estimatePi.R
library(foreach)
library(doParallel)
# Estimate value of pi using simulation
mcPi <- function(n=1e6) 4 * sum( runif(n)^2 + runif(n)^2 < 1) / n
# Set up cluster
cl <- makeCluster(4)
View rrt-checkpoint.R
# Create RRT repo checkpoint
library(RRT)
checkpoint("2014-08-28")
rrt_browse()
@andrie
andrie / 1-miniCRAN.R
Last active Apr 2, 2018
Introduction to miniCRAN
View 1-miniCRAN.R
# Install package from CRAN
getOption("repos")
options(repos=c(CRAN="http://cran.at.r-project.org/"))
install.packages("miniCRAN", type="source")
library("miniCRAN")
sessionInfo()
View checkpoint-use.R
library(checkpoint)
checkpoint("2014-09-17")
@andrie
andrie / checkpoint-install.R
Created Oct 8, 2014
Installing checkpoint
View checkpoint-install.R
install.packages("checkpoint")
library("checkpoint")
@andrie
andrie / checkpoint-example.R
Created Oct 8, 2014
Worked example of checkpoint
View checkpoint-example.R
# Create temporary project and set working directory
example_project <- paste0("~/checkpoint_example_project_", Sys.Date())
dir.create(example_project, recursive = TRUE)
oldwd <- setwd(example_project)
# Write dummy code file to project
@andrie
andrie / run-urbanek-benchmark-25.R
Created Oct 16, 2014
Source Simon Urbanek's benchmark v2.5 and capture total execution time
View run-urbanek-benchmark-25.R
# Run Simon Urbanek's benchmark v2.5
cat("R version\n")
cat("=========\n")
print(R.version)
if(exists("Revo.version")) {
cat("Revo version")
cat("============")
print(Revo.version)
@andrie
andrie / rro-mkl-benchmark.R
Last active Aug 29, 2015
Test performance of Intel MKL on matrix operations
View rro-mkl-benchmark.R
# Set MKL threads if Revolution R Open or Revolution R Enterprise is available
if(require("RevoUtilsMath")){
setMKLthreads(4)
}
# Initialization
set.seed (1)
@andrie
andrie / setSnapshot.R
Created Nov 18, 2014
Easily set a snapshot date on MRAN
View setSnapshot.R
setSnapshot <- function(date){
if(missing(date)) return(getOption("repos"))
repoDate <- paste0("http://mran.revolutionanalytics.com/snapshot/", date)
response <- tryCatch(
suppressWarnings(readLines(repoDate)),
error = function(e)e
)
if(inherits(response, "error")) stop(paste0("Invalid snapshot date."))
options(repos = c(CRAN = repoDate))
}
You can’t perform that action at this time.