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
#' A wrapper around base::findInterval() that allows decreasing values in the | |
#' value of the vector within which we wish to place values of x. | |
#' | |
#' When \code{vec} is in ascending order we use \code{base::findInterval()}, but | |
#' when \code{vec} is in descending order we implement an adaptation of the | |
#' \code{locate()} function from Numerical Recipes for C \url{http://apps.nrbook.com/c/index.html} | |
#' | |
#' @export | |
#' @param x numeric values we wish to located within \code{vec} | |
#' @param vec numeric vector of sorted values (ascending or descending order) |
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
# coastline.R | |
bb <- c(-72,-63,39,46) | |
#' Convert a bbox to sp::polygon, sp::Polygons, or sp::SpatialPolygons object | |
#' | |
#' @export | |
#' @param bb numeric, a 4-element bbox vector [left, right, bottom, top] | |
#' @param projstring character sutiable to pass to \code{sp::CRS}, | |
#' by default "+proj=longlat +datum=WGS84" | |
#' @param id character, the polygon ID, by default 'bbox' |
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
## | |
# Q: I need to mount a new NFS volume "0.1.2.3:/nfs/some_volume" on my linux server as a directory, "/mnt/my_volume" | |
## | |
## | |
# A: Mounting a volume requires these steps (thanks, Joe!) | |
## | |
# 1. Log in to the server where you have sudo privileges. |
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
#' Browse a dataset webpage. | |
#' | |
#' Note that it is an error to call this when \code{base::interactive()} returns FALSE | |
#' | |
#' @export | |
#' | |
#' @param datasetid Dataset id | |
#' @param x A datasetid or the output of \code{info} | |
#' @param url A URL for an ERDDAP server. Default: \url{http://upwell.pfeg.noaa.gov/erddap/} | |
#' @param ... Further args passed on to \code{\link[httr]{BROWSE}} (must be a named parameter) |
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(sp) | |
library(raster) | |
#' Extract valuers from a multilayer Raster* | |
#' | |
#' @param R a multilayer Raster* object | |
#' @param pts location info for points [cell, layer] or [row, col, layer] | |
#' @return a vector of values | |
layers_extractPoints <- function(R, pts){ | |
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
#' Perform grepl on multiple patterns; it's like AND-ing or OR-ing successive grepl statements. | |
#' | |
#' Adapted from https://stat.ethz.ch/pipermail/r-help/2012-June/316441.html | |
#' | |
#' @param pattern character vector of patterns | |
#' @param x the character vector to search | |
#' @param op logical vector operator back quoted, defaults to `|` | |
#' @param ... further arguments for \code{grepl} like \code{fixed} etc. | |
#' @return logical vector | |
mgrepl <- function(pattern, x, op = `|`, ... ){ |
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
#' Split a vector into groups of MAX (or possibly fewer) | |
#' | |
#' @param v vector or list to split | |
#' @param MAX numeric the maximum size per group | |
#' @return a list of the vector split into groups | |
split_vector <- function(v, MAX = 200){ | |
nv <- length(v) | |
if (nv <= MAX) return(list('1' = v)) | |
split(v, findInterval(1:nv, seq(from = 1, to = nv, by = MAX))) | |
} |
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
#' Access the cs2cs function from R | |
#' | |
#' @seealso http://proj4.org/index.html | |
#' | |
#' @param x numeric or character input value for x (longitude) | |
#' @param y numeric or character input value for y (latitude) | |
#' @param from character input coordinate system definition | |
#' @param to character output coordinate system definition | |
#' @param extra character extra arguments for cs2cs | |
#' @param app character the fully qualified path to the cs2cs executable |
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
#' A function to audit disk usage by subdirectory | |
#' | |
#' @param path the path to audit | |
#' @param extra character extra arguments for linux `du` command | |
#' @param app character the `du` executable path | |
#' @return data frame or NULL | |
#' \itemize{ | |
#' \item{size numeric in megabytes} | |
#' \item{name character} | |
#' } |
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
#' Compute the union of a list of vectors | |
#' | |
#' @param x a list of zero or more vectors | |
#' @return a vector of the union or NULL is the input is empty | |
munion <- function(x){ | |
if (!is.list(x)) stop("input must be a list") | |
n <- length(x) | |
if (n == 0) return(NULL) | |
if (n == 1) return(x[[1]]) |
OlderNewer