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
eval({ | |
ensure_nonnull <- ensures_that(!is.null(.) ~ "Must not be NULL" ) | |
ensure_nonempty <- ensures_that(length(.) > 0 ~ "Must not be empty", +ensure_nonnull ) | |
ensure_finite <- ensures_that(all(is.finite(.)) ~ "Must be finite", +ensure_nonempty ) | |
ensure_positive <- ensures_that(all(. > 0) ~ "Must be positive", +ensure_finite ) | |
ensure_nonnegative <- ensures_that(all(. >= 0) ~ "Must be positive or zero", +ensure_finite ) | |
ensure_unique <- ensures_that(length(unique(.)) == 1) | |
}) | |
# Wrapped in `eval({...})` b/c otherwise RStudio will complain about syntax |
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
# 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
# | |
#/** | |
# * Copyright 2007 The Apache Software Foundation | |
# * | |
# * Licensed to the Apache Software Foundation (ASF) under one | |
# * or more contributor license agreements. See the NOTICE file | |
# * distributed with this work for additional information | |
# * regarding copyright ownership. The ASF licenses this file | |
# * to you under the Apache License, Version 2.0 (the | |
# * "License"); you may not use this file except in compliance |
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
<?xml version="1.0"?> | |
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?> | |
<!-- Put site-specific property overrides in this file. --> | |
<configuration> | |
<property> | |
<name>fs.default.name</name> | |
<value>hdfs://localhost:9000</value> | |
</property> |
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
#' format_signif | |
#' | |
#' Format numbers with a given number of significant digits | |
#' | |
#' @param x numeric vector | |
#' @param digits number of significant digits | |
#' @return character vector | |
#' @examples | |
#' x <- c(0.800, 1704.1, 43.5e6, 10, NaN, NA, Inf, 0.00) | |
#' format_signif(x, digits=3) |
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(ggplot2) | |
require(scales) | |
seq_range <- function(x, by) seq(min(x), max(x), by=by) | |
time_breaks <- function(width) { | |
function(limits) seq_range(limits, by=width) | |
} | |
scale_x_hours <- function( |
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
#' fast_POSIXct | |
#' | |
#' Quickly convert local timestamps to a POSIXct vector | |
#' | |
#' @param x timestamps (YYYY-mm-dd HH:MM:SS) | |
#' @param tz local timezone | |
#' @return POSIXct vector | |
#' @export | |
fast_POSIXct <- function(x, tz) { | |
stopifnot(is.character(x)) |
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
#' aggregate.data.table | |
#' | |
#' Use to quickly aggregate rows from a data.frame | |
#' | |
#' @param x data.table | |
#' @param by list of columns to use for grouping | |
#' @param FUN summary function | |
#' @param \dots further arguments to summary function | |
#' @param is.value determines which of the remaining columns should be aggregated (numeric, POSIXct, character, etc.) | |
#' @author David Holstius \email{david.holstius@berkeley.edu} |