This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print.cintanotes <- function(x, ...) { | |
for (i in 1:nrow(x)) { | |
cat("#", x[i, 2], "\n\n") | |
cat(paste("Posted on *", x[i, 4], "*\n\n", sep = "")) | |
cat(x[i, 3], "\n\n") | |
if (x[i, 5] != "") { | |
cat("Links: ", x[i, 5], "\n\n") | |
} | |
if (!is.na(x[i, 6])) { | |
cat("Tags: ", x[i, 6], "\n\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm(dtt) ## Make sure `dtt` isn't there to begin with | |
set.seed(1) | |
LLLL <- apply(expand.grid(LETTERS, LETTERS[10:15], LETTERS[1:20], LETTERS[1:5], stringsAsFactors=FALSE), 1, paste0, collapse="") | |
size <- 1000 | |
dateSamples <- 1500 | |
startDate <- as.Date("1980-01-01") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myAgg <- function (formula, data, FUN, ..., subset, na.action = na.omit) | |
{ | |
if (missing(formula) || !inherits(formula, "formula")) | |
stop("'formula' missing or incorrect") | |
if (length(formula) != 3L) | |
stop("'formula' must have both left and right hand sides") | |
m <- match.call(expand.dots = FALSE) | |
if (is.matrix(eval(m$data, parent.frame()))) | |
m$data <- as.data.frame(data) | |
m$... <- m$FUN <- NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
read.so <- function(sep = "", header = TRUE, out = "mydf") { | |
OS <- ifelse(Sys.info()["sysname"] == "Darwin", "Mac", "others") | |
temp <- switch( | |
OS, | |
Mac = { | |
suppressWarnings( | |
read.table(text = gsub("^#", "", pipe("pbpaste")), header = header, | |
stringsAsFactors = FALSE, sep = sep)) | |
}, | |
others = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list.depth <- function(this, thisdepth = 0) { | |
# http://stackoverflow.com/a/13433689/1270695 | |
if(!is.list(this)) { | |
return(thisdepth) | |
} else { | |
return(max(unlist(lapply(this, list.depth, thisdepth = thisdepth+1)))) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parse_so_rep_page <- function(rep_file) { | |
# Authors: Paul Hiemstra, Ananda Mahto | |
all_data <- readLines(rep_file) | |
all_data <- all_data[-1] | |
## Deal with bonuses | |
all_data <- gsub("-- bonuses\\s+(.*)", " 99 NA \\1", all_data) | |
date_entries <- grep("^-", all_data) | |
actions_per_day <- c(date_entries[1], diff(date_entries)) - 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#'Download a Stack Overflow question page as a character vector | |
#' | |
#'Helper function for other Stack Overflow related functions. Downloads the | |
#'page as a character vector and extracts the portion that is needed for other | |
#'functions. | |
#' | |
#'@param qid The numeric question ID. | |
#'@return A character vector | |
#' | |
#'@author Ananda Mahto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
readClip <- function(){ | |
OS <- Sys.info()["sysname"] | |
cliptext <- switch(OS, | |
Darwin = { | |
con <- pipe("pbpaste") | |
text <- readLines(con) | |
close(con) | |
text | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uReshape <- function(data, id.vars, var.stubs, sep) { | |
vGrep <- Vectorize(grep, "pattern", SIMPLIFY = FALSE) | |
temp <- names(data)[names(data) %in% | |
unlist(vGrep(var.stubs, names(data), | |
value = TRUE))] | |
if (sep == "NoSep") { | |
x <- NoSep(temp, ...) | |
} else { | |
x <- do.call(rbind.data.frame, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uReshape <- function(data, id.vars, var.stubs, sep) { | |
# vectorized version of grep | |
vGrep <- Vectorize(grep, "pattern", SIMPLIFY = FALSE) | |
# Isolate the columns starting with the var.stubs | |
temp <- names(data)[names(data) %in% unlist(vGrep(var.stubs, names(data), value = TRUE))] | |
# Split the vector and reasemble into a data.frame | |
x <- do.call(rbind.data.frame, strsplit(temp, split = sep)) | |
names(x) <- c("VAR", paste(".time", 1:(length(x)-1), sep = "_")) |