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
--- | |
title: "Reactive Leaflet" | |
author: "David Holstius" | |
date: "April 16, 2015" | |
output: html_document | |
runtime: shiny | |
--- | |
## Problem Description |
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
extract_substrings <- function (x, ...) { | |
make_extractor <- function (i) { | |
#message(min(i), " to ", max(i)) | |
function (s) substr(s, min(i), max(i)) | |
} | |
extractors <- lapply(list(...), make_extractor) | |
lapply(extractors, function (f) f(x)) | |
} | |
ALPHABET <- paste0(LETTERS, collapse = "") |
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
library(ensurer) | |
ensure_none_missing <- ensures_that(!any(is.na(.)) ~ "There are missing values") | |
ensure_all_positive <- ensures_that(all(int(.)) > 0 ~ "Not all values are positive", +ensure_none_missing) | |
# Everything works as expected with a simple vector | |
x <- 1:4 | |
x %>% ensure_all_positive | |
# Now let's try testing element(s) of a 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
require(pachube) | |
key <- 'bZW0wu4jbqMrkzHhapw8E9...' # use your API key here | |
t0 <- ISOdate(2012, 05, 23, hour=19, tz="America/Los_Angeles") | |
z <- getDatapoints(58785, 'large', key, start=t0, interval=30, duration='12hours') | |
plot(z) |
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
key <- 'bZW0wu4jbqMrkzHhapw8E9...' # use your API key here | |
t0 <- ISOdate(2012, 05, 23, hour=19, tz="America/Los_Angeles") | |
z <- getDatapoints(58785, 'large', key, start=t0, interval=30, duration='12hours') |
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
key <- 'bZW0wu4jbqMrkzHhapw8E9...' # use your API key here | |
t0 <- ISOdate(2012, 05, 23, hour=19, tz="America/Los_Angeles") | |
z <- getDatapoints(58785, 'large', key, start=t0, interval=30, duration='12hours') | |
plot(z) |
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
key <- 'bZW0wu4jbqMrkzHhapw8E9...' # use your API key here | |
t0 <- ISOdate(2012, 05, 23, hour=19, tz="America/Los_Angeles") | |
z <- getDatapoints(58785, 'large', key, start=t0, interval=30, duration='12hours') | |
plot(z) |
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
require(cosm) | |
key <- 'bZW0wu4jbqMrkzHhap...' # your API key here | |
z <- feed_history(58785, key, duration='3hours') | |
plot(z) |
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
require('cosm') | |
if (!exists('key')) key <- readline('API key: ') | |
feed <- getFeed(58537, key) | |
print(feed$description) | |
t0 <- Sys.time() | |
duration <- 60 * 60 * 24 * 7 # one week | |
z <- getDatapoints(feed, key, datastreams='2h', end=t0, start=t0-duration) |
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.serlog | |
#' | |
#' Read CSV records from a file written by serlog.py | |
#' | |
#' @param file filename | |
#' @param varnames column names for the resulting \link{zoo} object | |
#' @export | |
read.serlog <- function(file, varnames) { | |
require(zoo) | |
options(digits.secs=3) |