Skip to content

Instantly share code, notes, and snippets.

@flodel
flodel / peachtree_2015
Created Jul 12, 2015
Script to scrape the 2015 AJC Peachtree Road Race results
View peachtree_2015
#############################################################################
## DOWNLOAD and PARSE data
base_url <- "http://trackshackresults.com/peachtree/results/2015/ptresults.php"
divisions_map <- read.table(text = '
Ind Div Division
1 1B "****MEN -- OPEN****"
2 1G "****WOMEN -- OPEN****"
View ok.comma.R
ok.comma <- function(FUN) {
function(...) {
arg.list <- as.list(sys.call())[-1L]
len <- length(arg.list)
if (len > 1L) {
last <- arg.list[[len]]
if (missing(last)) {
arg.list <- arg.list[-len]
}
}
View decode_examples.R
decode(basket, search = c("banana", "orange"),
replace = c("apple", "pineapple"))
# [1] "apple" "apple" "lemon" "pineapple" "pineapple" "pear" "cherry"
decode(basket, search = c("banana", "orange"),
replace = c("apple", "pineapple"),
default = "fig")
# [1] "fig" "apple" "fig" "pineapple" "pineapple" "fig" "fig"
View nested_ifelse.R
basket <- c("apple", "banana", "lemon", "orange",
"orange", "pear", "cherry")
ifelse(basket == "banana", "apple",
ifelse(basket == "orange", "pineapple",
basket)) # or "fig"))
# [1] "apple" "apple" "lemon" "pineapple"
# [4] "pineapple" "pear" "cherry"
View decode.R
decode <- function(x, search, replace, default = NULL) {
# build a nested ifelse function by recursion
decode.fun <- function(search, replace, default = NULL)
if (length(search) == 0L) {
function(x) if (is.null(default)) x else rep(default, length(x))
} else {
function(x) ifelse(x == search[1L], replace[1L],
decode.fun(tail(search, -1L),
tail(replace, -1L),
@flodel
flodel / optical.art.R
Created Jul 17, 2012
[R] optical art
View optical.art.R
optical.art <- function(P, N, colors = brewer.pal(P, "Greys")) {
## This function creates an Op art figure as can be found on
## http://r-de-jeu.blogspot.com/
##
## Inputs:
## - P: (integer) number of starting points
## - N: (integer) number of semi-lines starting from each point.
## For best results, N should be a multiple of P
## - colors: vector of colors for filling polygons.
@flodel
flodel / image.gallery.R
Created May 2, 2012
Basic Craigslist API
View image.gallery.R
@flodel
flodel / gist:2523299
Created Apr 29, 2012
[R] Create word cloud of most used packages
View gist:2523299
library(wordcloud)
wordcloud(packages.df$`Package Name`,
packages.df$Users,
max.words = 50,
colors = brewer.pal(9, "Greens")[4:9])
@flodel
flodel / gist:2523265
Created Apr 29, 2012
[R] Scrape crantastic.org for most used packages
View gist:2523265
library(plyr)
library(XML)
# build a vector of URL pages we'll want to use
urls <- paste("http://crantastic.org/popcon?page=", 1:10, sep = "")
# scrape all the data from the URLs into one big data.frame
packages.df <- ldply(urls, function(url)readHTMLTable(url)[[1]])
# turn the "Users" column from factor to numeric
You can’t perform that action at this time.