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
titlecase <- function (x) { | |
# TODO: use Rex package | |
gsub("\\b([a-z])([a-z]+)", "\\U\\1\\L\\2", tolower(x), perl = TRUE) | |
} |
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
.DS_Store | |
build | |
node_modules |
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_tbl <- function (..., stringsAsFactors = FALSE, check.names = FALSE) { | |
require(dplyr) | |
as.tbl(read.csv(..., stringsAsFactors = stringsAsFactors, check.names = check.names)) | |
} | |
write_tbl <- function (x, ..., row.names = FALSE) { | |
write.csv(as.tbl(x), ..., row.names = row.names) | |
} |
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
merge.SpatialPolygonsDataFrame <- function (x, y, by, ...) { | |
require(sp) | |
y <- as.data.frame(y) | |
if (missing(by)) { | |
if (is.null(row.names(x@data)) || is.null(row.names(y))) { | |
warning("[merge.SpatialPolygonsDataFrame] merging by position") | |
i <- 1:nrow(x@data) | |
} else { | |
warning("[merge.SpatialPolygonsDataFrame] merging by row names") | |
i <- row.names(x@data) |
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
# Installation | |
library(devtools) | |
install_github("BAAQMD/CalEnviroScreen") | |
# Helper function: merge.SpatialPolygonsDataFrame() | |
source_gist("8d1aa85a1623243f8f1f") | |
# Data from CalEnviroScreen 2 (CES2) package | |
data(California, package = "CalEnviroScreen") | |
data(CES2, package = "CalEnviroScreen") |
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
suppressPackageStartupMessages({ | |
library(dplyr) # install.packages("dplyr") | |
library(tidyr) # install.packages("tidyr") | |
library(httr) # install.packages("httr") | |
library(lubridate) # install.packages("lubridate") | |
library(stringr) # install.packages("stringr") | |
library(ggvis) # install.packages("ggvis") | |
library(digest) # install.packages("digest") | |
}) |
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
abline_data <- function (domain, intercept, slope) { | |
data.frame(x = domain, y = domain * slope + intercept) | |
} | |
untick <- function (x) { | |
stopifnot(all(sapply(x, is.name))) | |
str_replace_all(as.character(x), "`", "") | |
} | |
layer_abline <- function (.vis, domain, intercept = 0, slope = 1, dash = 6, ...) { |
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
optim_lag <- function (z1, z2, merit = cor, max_lag = 120, warn = FALSE) { | |
require(zoo) | |
ow <- as.integer(options("warn")) | |
options(warn = -1 * as.integer(!warn)) | |
on.exit(options(warn = ow)) | |
f <- approxfun(x = index(z2), y = as.numeric(z2)) | |
t_start <- max(start(z1), start(z2)) | |
t_end <- min(end(z1), end(z2)) | |
z1 <- window(z1, start = t_start, end = t_end) | |
z2 <- window(z2, start = t_start, end = t_end) |
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
# Ported by David Holstius <dholstius@baaqmd.gov> | |
# from http://skip.ucsc.edu/leslie_MOUSE/programs/plotting/tsreg.r | |
# Module tsreg | |
# Author: E. A. Houseman | |
# Last update July 2004 | |
# AR(q) time series regression assuming regular intervals | |
# Support for cholesky residuals [Houseman, Ryan, Coull (2004, JASA)] |
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
rbindapply <- function ( | |
X, | |
FUN, | |
... | |
) { | |
results <- lapply(X, FUN, ...) | |
if (!is.null(names(X))) { | |
names(results) <- names(X) | |
} else { | |
if (is.character(X)) |