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
# See http://stackoverflow.com/questions/29310962/variant-of-rgeosgunion-that-wont-dissolve-adjacent-polygons | |
# for the relevant problem formulation. | |
library(sp) | |
unit_rect <- cbind( | |
x = c(0, 0, 1, 1, 0), | |
y = c(0, 1, 1, 0, 0)) | |
translate <- function (spobj, delta = c(0, 0)) { |
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
#' Patch data on the fly. | |
#' | |
#' @param object to be patched | |
#' @param cond logical condition(s) to be evaluated within scope of object | |
#' @param \dots name-value pairs | |
#' @param quiet suppress messages | |
#' | |
#' @examples | |
#' patch(mtcars, where(vs == 0, am == 1), gear = Inf, carb = carb + 10) | |
#' |
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
#' (Left) join with a custom comparator | |
#' | |
#' @param left data.frame | |
#' @param right data.frame | |
#' @param by names of columns to join by | |
#' @param fun custom comparator (see examples) | |
#' | |
#' @examples | |
#' my_df <- data.frame(cyl = c(4, 4, 6, 8), vs = c(0, 1, NA, NA), foo = c("A", "B", "C", "D")) | |
#' my_fun <- function (e1, e2) (e1 == e2) | is.na(e2) |
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
# via https://support.rstudio.com/hc/en-us/articles/200552326-Running-RStudio-Server-with-a-Proxy | |
user nginx; | |
worker_processes 4; | |
# daemon off; | |
pid /run/nginx.pid; | |
events { | |
worker_connections 768; | |
# multi_accept on; |
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
install_from_source <- function (pkg, args = NULL, repos = "http://cran.rstudio.com", overwrite = FALSE, ...) { | |
if (!overwrite) { | |
if (pkg %in% installed.packages()) { | |
message(pkg, " is already installed") | |
return() | |
} | |
} | |
install.packages( |
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
#' Filter (subset) a Spatial*DataFrame object | |
#' | |
#' @param object a \code{Spatial*DataFrame} | |
#' @param ... see \link{subset} | |
#' @param .dots | |
#' | |
#' @importFrom lazyeval all_dots lazy_eval | |
#' | |
#' @return a subset of the original \code{Spatial*DataFrame} | |
#' |
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) # awesome | |
# Example 1 --- OK | |
groceries <- c("eggs", "bread", "milk") | |
check_that(groceries, "bread" %in% .) | |
# Example 2 --- :-( | |
# I'd really like this to work! It's quite readable. | |
# Doesn't work b/c `ensurer` (v1.1) doesn't first evaluate calls. | |
contains <- function (what) function (x) { what %in% x } |