diff --git a/DESCRIPTION b/DESCRIPTION index e889b9c..dde3929 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: inlmisc Title: Miscellaneous Functions for the USGS INL Project Office -Version: 0.4.3.9000 +Version: 0.4.4 Authors@R: person(given=c("Jason", "C."), family="Fisher", role=c("aut", "cre"), email="jfisher@usgs.gov", comment=c(ORCID="0000-0001-9032-8912")) Description: A collection of functions for creating high-level graphics, performing raster-based analysis, processing MODFLOW-based models, @@ -12,7 +12,7 @@ Depends: R (>= 3.4.0) Imports: checkmate, - dplyr, + data.table, GA, graphics, grDevices, diff --git a/Makefile b/Makefile index 9b42b1c..018316d 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,8 @@ PKGSRC := $(shell basename `pwd`) all: docs install check docs: - R -q -e 'devtools::document()';\ - R -q -e 'devtools::clean_dll()';\ + R -q -e 'Rd2roxygen::roxygen_and_build('\''.'\'', build=FALSE, reformat=FALSE)';\ + R -q -e 'pkgbuild::clean_dll()';\ build: cd ..;\ diff --git a/NAMESPACE b/NAMESPACE index 3db4ac9..4e9c6d7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,7 @@ export(AddNorthArrow) export(AddPoints) export(AddScaleBar) export(AddSearchButton) +export(BuildVignettes) export(BumpDisconnectCells) export(BumpRiverStage) export(CreateWebMap) @@ -44,5 +45,6 @@ export(SetPolygons) export(SummariseBudget) export(ToScientific) import(rgdal) +importFrom(data.table,data.table) importFrom(igraph,clusters) useDynLib(inlmisc, .registration=TRUE, .fixes="C_") diff --git a/NEWS.md b/NEWS.md index 2a49013..1eb4dd8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,10 @@ -# inlmisc 0.4.3.9000 +# inlmisc 0.4.4 + +- Add `BuildVignettes` function, used to build package vignettes. + +- In `SummariseBudget` function, improve memory management. + +- Change package imports by adding **data.table** and removing **dplyr**. - Add `SetHinge` function, used to specify a hinge location in a color palette. diff --git a/R/BuildVignettes.R b/R/BuildVignettes.R new file mode 100644 index 0000000..8840fb9 --- /dev/null +++ b/R/BuildVignettes.R @@ -0,0 +1,53 @@ +#' Build Package Vignettes +#' +#' Build package vignettes from their sources and place in the \code{/inst/doc} folder. +#' +#' @param pkg 'character' string. +#' Package path, by default the \link[=getwd]{working directory}. +#' @param quiet 'logical' flag. +#' Whether to supress most output. +#' @param clean 'logical' flag. +#' Whether to remove all intermediate files generated by the build. +#' @param gs_quality 'character' string. +#' Quality of compacted PDF files, +#' see \code{\link[tools]{compactPDF}} function for details. +#' +#' @author J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center +#' +#' @seealso \code{\link[tools]{buildVignettes}} +#' +#' @keywords utilities +#' +#' @export +#' +#' @examples +#' \dontrun{ +#' BuildVignettes("", gs_quality = "ebook") +#' } +#' + +BuildVignettes <- function(pkg=".", quiet=TRUE, clean=TRUE, gs_quality=NULL) { + + checkmate::assertFileExists(file.path(pkg, "DESCRIPTION")) + checkmate::assertFlag(quiet) + checkmate::assertFlag(clean) + if (!is.null(gs_quality)) + gs_quality <- match.arg(gs_quality, c("none", "printer", "ebook", "screen")) + + tools::buildVignettes(dir=pkg, quiet=quiet, clean=clean, tangle=TRUE) + + v <- tools::pkgVignettes(dir=pkg, output=TRUE, source=TRUE) + if (length(v) == 0) return(invisible(NULL)) + out <- c(v$outputs, unique(unlist(v$sources, use.names=FALSE))) + + doc <- file.path(pkg, "inst/doc") + + dir.create(doc, showWarnings=!quiet, recursive=TRUE) + file.copy(c(v$docs, out), doc, overwrite=TRUE) + file.remove(out) + + if (!is.null(gs_quality)) + tools::compactPDF(paths=doc, gs_quality=gs_quality) + + invisible(TRUE) +} diff --git a/R/ExportRasterStack.R b/R/ExportRasterStack.R index 20fc1db..9b511b5 100644 --- a/R/ExportRasterStack.R +++ b/R/ExportRasterStack.R @@ -60,13 +60,11 @@ ExportRasterStack <- function(rs, path, zip="", col=NULL) { # check arguments stopifnot(inherits(rs, c("RasterStack", "RasterBrick"))) - checkmate::assertDirectoryExists(path) + checkmate::assertString(path) checkmate::assertString(zip) if (zip != "") checkmate::assertFileExists(zip) checkmate::assertCharacter(col, null.ok=TRUE) - if (is.null(col)) col <- GetColors(255, stops=c(0.3, 0.9)) - dir.create(path, showWarnings=FALSE, recursive=TRUE) dir.create(path.csv <- file.path(path, "csv"), showWarnings=FALSE) dir.create(path.png <- file.path(path, "png"), showWarnings=FALSE) @@ -74,6 +72,8 @@ ExportRasterStack <- function(rs, path, zip="", col=NULL) { dir.create(path.rda <- file.path(path, "rda"), showWarnings=FALSE) dir.create(path.kml <- file.path(path, "kml"), showWarnings=FALSE) + if (is.null(col)) col <- GetColors(255, stops=c(0.3, 0.9)) + n <- 0L for (i in names(rs)) { n <- n + 1L diff --git a/R/GetColors.R b/R/GetColors.R index adfd533..8320531 100644 --- a/R/GetColors.R +++ b/R/GetColors.R @@ -92,7 +92,12 @@ #' Generic Mapping Tools: Improved version released, AGU, v. 94, no. 45, p. 409--410 #' doi:\href{https://doi.org/10.1002/2013EO450001}{10.1002/2013EO450001} #' -#' @seealso \code{\link{SetHinge}}, \code{\link[grDevices]{col2rgb}} +#' @seealso +#' \code{\link{SetHinge}} function to set the hinge location in +#' a color palette derived from one or two color schemes. +#' +#' \code{\link[grDevices]{col2rgb}} function to express palette +#' colors represented in the hexadecimal format as RGB triplets (R, G, B). #' #' @keywords color #' diff --git a/R/ReadCodeChunks.R b/R/ReadCodeChunks.R index 3800ab5..73af05e 100644 --- a/R/ReadCodeChunks.R +++ b/R/ReadCodeChunks.R @@ -25,6 +25,7 @@ #' @export #' #' @examples +#' \dontrun{ #' file <- system.file("misc", "knitr-markdown.Rmd", package = "inlmisc") #' chunks <- ReadCodeChunks(file) #' @@ -33,6 +34,7 @@ #' chunks[["named-chunk-2"]] #' #' eval(parse(text = unlist(chunks[c("unnamed-chunk-3", "named-chunk-4")]))) +#' } #' ReadCodeChunks <- function(path) { diff --git a/R/ReadModflowBinary.R b/R/ReadModflowBinary.R index 2f68ed7..21687ed 100644 --- a/R/ReadModflowBinary.R +++ b/R/ReadModflowBinary.R @@ -67,9 +67,9 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"), endian <- match.arg(endian) checkmate::assertFlag(rm.totim.0) - ans <- try(.ReadBinary(path, data.type, endian, nbytes=4), silent=TRUE) + ans <- try(.ReadBinary(path, data.type, endian, nbytes=4L), silent=TRUE) if (inherits(ans, "try-error")) - ans <- .ReadBinary(path, data.type, endian, nbytes=8) + ans <- .ReadBinary(path, data.type, endian, nbytes=8L) if (rm.totim.0) ans <- ans[vapply(ans, function(i) i$totim, 0) != 0] ans @@ -81,7 +81,7 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"), checkmate::assertFileExists(path) checkmate::assertString(data.type) checkmate::assertString(endian) - stopifnot(nbytes %in% c(4, 8)) + stopifnot(nbytes %in% c(4L, 8L)) con <- file(path, open="rb", encoding="bytes") on.exit(close(con, type="rb")) @@ -136,33 +136,33 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"), "wells") lst <- list() repeat { - kstp <- readBin(con, "integer", n=1, size=4, endian=endian) + kstp <- readBin(con, "integer", n=1L, size=4L, endian=endian) if (length(kstp) == 0) break - kper <- readBin(con, "integer", n=1, size=4, endian=endian) + kper <- readBin(con, "integer", n=1L, size=4L, endian=endian) if (data.type == "array") { - pertim <- readBin(con, "numeric", n=1, size=nbytes, endian=endian) - totim <- readBin(con, "numeric", n=1, size=nbytes, endian=endian) - desc <- readBin(readBin(con, "raw", n=16, size=1, endian=endian), - "character", n=1, endian=endian) + pertim <- readBin(con, "numeric", n=1L, size=nbytes, endian=endian) + totim <- readBin(con, "numeric", n=1L, size=nbytes, endian=endian) + desc <- readBin(readBin(con, "raw", n=16L, size=1L, endian=endian), + "character", n=1L, endian=endian) desc <- .TidyDescription(desc) if (!desc %in% valid.desc) break - ncol <- readBin(con, "integer", n=1, size=4, endian=endian) - nrow <- readBin(con, "integer", n=1, size=4, endian=endian) - layer <- readBin(con, "integer", n=1, size=4, endian=endian) + ncol <- readBin(con, "integer", n=1L, size=4L, endian=endian) + nrow <- readBin(con, "integer", n=1L, size=4L, endian=endian) + layer <- readBin(con, "integer", n=1L, size=4L, endian=endian) v <- readBin(con, "numeric", n=nrow * ncol, size=nbytes, endian=endian) d <- matrix(v, nrow=nrow, ncol=ncol, byrow=TRUE) lst[[length(lst) + 1]] <- list(d=d, kstp=kstp, kper=kper, desc=desc, layer=layer, pertim=pertim, totim=totim) } else if (data.type == "flow") { - desc <- readBin(readBin(con, "raw", n=16, size=1, endian=endian), - "character", n=1, endian=endian) + desc <- readBin(readBin(con, "raw", n=16L, size=1L, endian=endian), + "character", n=1L, endian=endian) desc <- .TidyDescription(desc) if (!desc %in% valid.desc) break - ncol <- readBin(con, "integer", n=1, size=4, endian=endian) - nrow <- readBin(con, "integer", n=1, size=4, endian=endian) - nlay <- readBin(con, "integer", n=1, size=4, endian=endian) + ncol <- readBin(con, "integer", n=1L, size=4L, endian=endian) + nrow <- readBin(con, "integer", n=1L, size=4L, endian=endian) + nlay <- readBin(con, "integer", n=1L, size=4L, endian=endian) if (nlay > 0) { x <- .Read3dArray(con, nrow, ncol, nlay, nbytes, endian) @@ -173,26 +173,25 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"), } else { # compact form is used nlay <- abs(nlay) - itype <- readBin(con, "integer", n=1, size=4, endian=endian) - delt <- readBin(con, "numeric", n=1, size=nbytes, endian=endian) - pertim <- readBin(con, "numeric", n=1, size=nbytes, endian=endian) - totim <- readBin(con, "numeric", n=1, size=nbytes, endian=endian) + itype <- readBin(con, "integer", n=1L, size=4L, endian=endian) + delt <- readBin(con, "numeric", n=1L, size=nbytes, endian=endian) + pertim <- readBin(con, "numeric", n=1L, size=nbytes, endian=endian) + totim <- readBin(con, "numeric", n=1L, size=nbytes, endian=endian) - if (itype == 5) - nval <- readBin(con, "integer", n=1, size=4, endian=endian) + if (itype == 5L) + nval <- readBin(con, "integer", n=1L, size=4L, endian=endian) else nval <- 1L if (nval > 100) stop("more than one-hundred varaiables for each cell") if (nval > 1) { - ctmp <- readBin(readBin(con, "raw", n=16, size=1, endian=endian), - "character", n=nval - 1, endian=endian) + ctmp <- readBin(readBin(con, "raw", n=16L, size=1L, endian=endian), + "character", n=nval - 1L, endian=endian) ctmp <- .TidyDescription(ctmp) } else { ctmp <- NULL } - if (itype %in% c(0, 1)) { - nvalues <- ncol * nrow * nlay + if (itype %in% c(0L, 1L)) { d <- .Read3dArray(con, nrow, ncol, nlay, nbytes, endian) for (i in seq_along(d)) { lst[[length(lst) + 1]] <- list(d=d[[i]], kstp=kstp, kper=kper, @@ -200,46 +199,51 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"), pertim=pertim, totim=totim) } - } else if (itype %in% c(2, 5)) { - nlist <- readBin(con, "integer", n=1, size=4, endian=endian) + } else if (itype %in% c(2L, 5L)) { + nlist <- readBin(con, "integer", n=1L, size=4L, endian=endian) if (nlist > (nrow * ncol * nlay)) stop("large number of cells for which values will be stored") if (nlist > 0) { - d <- matrix(0, nrow=nlist, ncol=nval + 4) + d <- matrix(0, nrow=nlist, ncol=nval + 4L) colnames(d) <- make.names(c("icell", "layer", "row", "column", "flow", ctmp), unique=TRUE) for (i in seq_len(nlist)) { - d[i, 1] <- readBin(con, "integer", n=1, size=4, endian=endian) + d[i, 1] <- readBin(con, "integer", n=1L, size=4L, endian=endian) d[i, seq_len(nval) + 4] <- readBin(con, "numeric", n=nval, size=nbytes, endian=endian) } nrc <- nrow * ncol - d[, "layer"] <- as.integer((d[, "icell"] - 1) / nrc + 1) - d[, "row"] <- as.integer(((d[, "icell"] - (d[, "layer"] - 1) * nrc) - 1) / ncol + 1) - d[, "column"] <- as.integer(d[, "icell"] - (d[, "layer"] - 1) * nrc - (d[, "row"] - 1) * ncol) + d[, "layer"] <- as.integer((d[, "icell"] - 1L) / nrc + 1L) + d[, "row"] <- as.integer(((d[, "icell"] - (d[, "layer"] - 1L) * nrc) + - 1L) / ncol + 1L) + d[, "column"] <- as.integer(d[, "icell"] - (d[, "layer"] - 1L) + * nrc - (d[, "row"] - 1L) * ncol) lst[[length(lst) + 1]] <- list(d=d, kstp=kstp, kper=kper, desc=desc, delt=delt, pertim=pertim, totim=totim) } - } else if (itype == 3) { - layers <- readBin(con, "integer", n=nrow * ncol, size=4, endian=endian) + } else if (itype == 3L) { + layers <- readBin(con, "integer", n=nrow * ncol, size=4L, endian=endian) values <- readBin(con, "numeric", n=nrow * ncol, size=nbytes, endian=endian) for (i in sort(unique(layers))) { v <- values[layers == i] d <- matrix(v, nrow=nrow, ncol=ncol, byrow=TRUE) lst[[length(lst) + 1]] <- list(d=d, kstp=kstp, kper=kper, desc=desc, - layer=i, delt=delt, pertim=pertim, totim=totim) + layer=i, delt=delt, pertim=pertim, + totim=totim) } - } else if (itype == 4) { + } else if (itype == 4L) { v <- readBin(con, "numeric", n=nrow * ncol, size=nbytes, endian=endian) d <- matrix(v, nrow=nrow, ncol=ncol, byrow=TRUE) lst[[length(lst) + 1]] <- list(d=d, kstp=kstp, kper=kper, desc=desc, - layer=1, delt=delt, pertim=pertim, totim=totim) + layer=1L, delt=delt, pertim=pertim, + totim=totim) d[, ] <- 0 for (i in seq_len(nlay)[-1]) { lst[[length(lst) + 1]] <- list(d=d, kstp=kstp, kper=kper, desc=desc, - layer=i, delt=delt, pertim=pertim, totim=totim) + layer=i, delt=delt, pertim=pertim, + totim=totim) } } else { diff --git a/R/SetHinge.R b/R/SetHinge.R index a2c0fc7..1b1d8a2 100644 --- a/R/SetHinge.R +++ b/R/SetHinge.R @@ -3,14 +3,14 @@ #' The \emph{hinge} indicates a dramatic color change in a palette #' that is typically located at the midpoint of the data range. #' An asymmetrical data range can result in an undesired hinge location, -#' where the location does not necessarily coincide with the break-point in the user's data. -#' This function is used to specify a hinge location that is appropriate for your data. +#' a location that does not necessarily coincide with the break-point in the user's data. +#' This function can be used to specify a hinge location that is appropriate for your data. #' #' @param x 'numeric' object that can be passed to the \code{\link{range}} #' function with \code{NA}'s removed. -#' That is, the user's data range (such as, at sea-level). +#' The user's data range. #' @param hinge 'numeric' number. -#' Hinge value in data units. +#' Hinge value (such as, at sea-level) in data units. #' @param scheme 'character' vector of length 1 or 2, value is recycled as necessary. #' Name of color scheme(s). #' The color palette is derived from one or two color schemes. @@ -29,7 +29,7 @@ #' Values applied separately on either side of the hinge. #' @param stops 'numeric' vector of length 2. #' Color stops defined by interval endpoints (between 0 and 1) -#' and used to select a subset of the color palette. +#' and used to select a subset of the color palette(s). #' @param allow_bias 'logical' flag. #' Whether to allow bias in the color spacing. #' @@ -181,7 +181,7 @@ SetHinge <- function(x, hinge, scheme="sunset", alpha=NULL, reverse=FALSE, s1 <- c(stp[1] + adj[1], ran - buf[1]) s2 <- c(1 - ran + buf[2], 1 - stp[2] - adj[2]) - if (s1[1] >= s1[2] | s2[1] >= s2[2]) + if (s1[1] >= s1[2] || s2[1] >= s2[2]) stop("problem with color stops and (or) buffer values") FUN <- function(...) { diff --git a/R/SummariseBudget.R b/R/SummariseBudget.R index b0c1dcb..4c80820 100644 --- a/R/SummariseBudget.R +++ b/R/SummariseBudget.R @@ -20,7 +20,7 @@ #' Data in the MODFLOW cell-by-cell budget file must be saved using the #' \emph{\bold{"COMPACT BUDGET"}} output option. #' -#' @return Returns a 'data.frame' with the following variables: +#' @return Returns a 'data.table' with the following variables: #' \describe{ #' \item{desc}{description of data type, such as "wells".} #' \item{kper}{stress period} @@ -44,6 +44,8 @@ #' #' @keywords utilities #' +#' @importFrom data.table data.table +#' #' @export #' #' @examples @@ -59,15 +61,15 @@ SummariseBudget <- function(budget, desc=NULL, id=NULL) { checkmate::assertFileExists(budget) budget <- ReadModflowBinary(budget, "flow") } - checkmate::assertCharacter(desc, any.missing=FALSE, min.len=1, unique=TRUE, null.ok=TRUE) + checkmate::assertCharacter(desc, any.missing=FALSE, min.len=1, + unique=TRUE, null.ok=TRUE) checkmate::assertString(id, null.ok=TRUE) budget.desc <- vapply(budget, function(i) i$desc, "") - if (is.null(desc)) { - desc <- unique(budget.desc) - } else { + if (!is.null(desc)) { is <- desc %in% budget.desc - if (all(!is)) stop("data type(s) not found in budget") + if (all(!is)) + stop("data type(s) not found in budget") if (any(!is)) warning(sprintf("data type(s) not found in budget: %s", paste(paste0("\"", desc[!is], "\""), collapse=", "))) @@ -75,56 +77,44 @@ SummariseBudget <- function(budget, desc=NULL, id=NULL) { } is <- vapply(budget, function(x) !is.null(colnames(x$d)), FALSE) - if (all(!is)) stop("data type(s) not saved using correct form") + if (all(!is)) + stop("data type(s) not saved using correct form") if (any(!is)) { x <- unique(vapply(budget[!is], function(i) i$desc, "")) warning(sprintf("removed data type(s): %s not saved using correct form", - paste(paste0("\"", x, "\""), collapse=", "))) + paste(paste0("\"", x, "\""), collapse=", "))) } budget <- budget[is] - desc <- vapply(budget, function(i) i$desc, "") - - b <- budget - for (i in seq_along(b)) b[[i]]$d[b[[i]]$d[, "flow"] < 0, "flow"] <- 0 - d <- dplyr::mutate(.Summarise(b, desc, id), flow.dir="in") - - b <- budget - for (i in seq_along(b)) b[[i]]$d[b[[i]]$d[, "flow"] > 0, "flow"] <- 0 - d <- dplyr::bind_rows(d, dplyr::mutate(.Summarise(b, desc, id), flow.dir="out")) - - d$flow.dir <- as.factor(d$flow.dir) - d -} - -.Summarise <- function(b, desc, id) { + dt <- data.table::rbindlist(lapply(budget, function(x) { + d <- data.table::data.table(desc=x$desc, kper=x$kper, kstp=x$kstp, id=NA, + flow=x$d[, "flow"], delt=x$delt, + pertim=x$pertim, totim=x$totim) + if (!is.null(id) && id %in% colnames(x$d)) d$id <- x$d[, id] + d + })) + dt$desc <- as.factor(dt$desc) + dt$flow.dir <- as.character(NA) - checkmate::assertList(b) - checkmate::assertCharacter(desc) - checkmate::assertString(id, null.ok=TRUE) + # due to NSE notes in R CMD check + delt <- flow <- flow.dir <- kper <- kstp <- pertim <- totim <- NULL - d <- dplyr::bind_rows(lapply(desc, function(i) { - dplyr::bind_rows(lapply(b[desc == i], function(j) { - d <- data.frame(desc=j$desc, kper=j$kper, kstp=j$kstp, id=NA, - flow=j$d[, "flow"], delt=j$delt, - pertim=j$pertim, totim=j$totim, stringsAsFactors=FALSE) - if (!is.null(id) && id %in% colnames(j$d)) d$id <- j$d[, id] - d - })) + dt_summary <- data.table::rbindlist(lapply(c("in", "out"), function(i) { + if (i == "in") + dt$flow[dt$flow < 0] <- 0 + else + dt$flow[dt$flow > 0] <- 0 + dt[, list(delt = utils::head(delt, 1), + pertim = utils::head(pertim, 1), + totim = utils::head(totim, 1), + count = length(flow), + flow.sum = sum(flow), + flow.mean = mean(flow), + flow.median = stats::median(flow), + flow.sd = stats::sd(flow), + flow.dir = i), + by=list(desc, kper, kstp, id)] })) - d$desc <- as.factor(d$desc) - if ("id" %in% colnames(d)) - grps <- dplyr::group_by_(d, "desc", "kper", "kstp", "id") - else - grps <- dplyr::group_by_(d, "desc", "kper", "kstp") - d <- dplyr::summarise_(grps, - delt = "delt[1]", - pertim = "pertim[1]", - totim = "totim[1]", - count = "length(flow)", - flow.sum = "sum(flow)", - flow.mean = "mean(flow)", - flow.median = "stats::median(flow)", - flow.sd = "sd(flow)") - d + dt_summary$flow.dir <- as.factor(dt_summary$flow.dir) + dt_summary } diff --git a/inst/raw/README.md b/inst/raw/README.md index 25aac48..b721cdd 100644 --- a/inst/raw/README.md +++ b/inst/raw/README.md @@ -39,3 +39,9 @@ Open the *../../R/GetColors.R* file and specify the width in inches. ``` Note that a PDF viewer is currently used to determine the layout width. + +## Permissions + +* Thomas Dewez (SRON) granted permission to add his color schemes on October 17, 2018. + +* Paul Tol (SRON) granted permission to add his color schemes on October 17, 2018. diff --git a/inst/raw/internal-datasets.R b/inst/raw/internal-datasets.R index 9a79714..4987b31 100644 --- a/inst/raw/internal-datasets.R +++ b/inst/raw/internal-datasets.R @@ -1,30 +1,13 @@ MakeSysdata <- function() { options(stringsAsFactors=FALSE) + dir.create(file.path(getwd(), "cpt"), showWarnings=FALSE) cite <- c("Dewez" = "Thomas Dewez (2004) grants permission to distribute with attribution.", "Tol" = "Paul Tol (2018) grants permission to distribute with attribution.", "Wessel" = "Wessel and others (2013) released under an open license.") - exclude <- scan(what="character", quiet=TRUE, text=" - cool - grayC - polar - red2green - seis - ") - diverge <- scan(what="character", quiet=TRUE, text=" - berlin - broc - cork - lisbon - oleron - roma - split - tofino - vik - ") - schemes <- .GetGMTCpt(cite["Wessel"], exclude, diverge) + schemes <- .GetCptGmt(cite["Wessel"]) schemes[["DEM screen"]] <- list( data = read.csv(strip.white=TRUE, text=" @@ -501,7 +484,8 @@ MakeSysdata <- function() { } -.GetGMTCpt <- function(cite, exclude=NULL, diverge=NULL) { +.GetCptGmt <- function(cite) { + checkmate::assertString(cite) # code adapted from stackoverflow answer by lukeA, accessed October 27, 2018 # at https://stackoverflow.com/questions/25485216 @@ -514,24 +498,22 @@ MakeSysdata <- function() { httr::stop_for_status(info) tree <- unlist(lapply(httr::content(info)$tree, "[", "path"), use.names=FALSE) path <- grep("share/cpt/", tree, value=TRUE, fixed=TRUE) - host <- "raw.githubusercontent.com" file <- sprintf("https://%s/%s/%s/master/%s", host, owner, repo, path) nm <- tools::file_path_sans_ext(basename(file)) + exclude <- c("cool", "grayC", "polar", "red2green", "seis") file <- file[!nm %in% exclude] - destdir <- file.path(getwd(), "cpt") - dir.create(destdir, showWarnings=FALSE) - - destfile <- file.path(destdir, basename(file)) + destfile <- file.path(getwd(), "cpt", basename(file)) for (i in seq_along(file)) { utils::download.file(file[i], destfile[i], quiet=TRUE) } nm <- tools::file_path_sans_ext(basename(file)) type <- rep("Sequential", length(nm)) - type[nm %in% diverge] <- "Diverging" + div <- c("berlin", "broc", "cork", "lisbon", "oleron", "roma", "split", "tofino", "vik") + type[nm %in% div] <- "Diverging" cpt <- lapply(seq_along(destfile), function(i) { .ReadCpt(destfile[i], cite=cite, type=type[i]) diff --git a/man/BuildVignettes.Rd b/man/BuildVignettes.Rd new file mode 100644 index 0000000..e3105aa --- /dev/null +++ b/man/BuildVignettes.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/BuildVignettes.R +\name{BuildVignettes} +\alias{BuildVignettes} +\title{Build Package Vignettes} +\usage{ +BuildVignettes(pkg = ".", quiet = TRUE, clean = TRUE, + gs_quality = NULL) +} +\arguments{ +\item{pkg}{'character' string. +Package path, by default the \link[=getwd]{working directory}.} + +\item{quiet}{'logical' flag. +Whether to supress most output.} + +\item{clean}{'logical' flag. +Whether to remove all intermediate files generated by the build.} + +\item{gs_quality}{'character' string. +Quality of compacted PDF files, +see \code{\link[tools]{compactPDF}} function for details.} +} +\description{ +Build package vignettes from their sources and place in the \code{/inst/doc} folder. +} +\examples{ +\dontrun{ +BuildVignettes("", gs_quality = "ebook") +} + +} +\seealso{ +\code{\link[tools]{buildVignettes}} +} +\author{ +J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center +} +\keyword{utilities} diff --git a/man/GetColors.Rd b/man/GetColors.Rd index 609f631..6d6a2e2 100644 --- a/man/GetColors.Rd +++ b/man/GetColors.Rd @@ -206,7 +206,11 @@ Dewez, Thomas, 2004, Variations on a DEM palette, accessed October 15, 2018 at doi:\href{https://doi.org/10.1002/2013EO450001}{10.1002/2013EO450001} } \seealso{ -\code{\link{SetHinge}}, \code{\link[grDevices]{col2rgb}} +\code{\link{SetHinge}} function to set the hinge location in + a color palette derived from one or two color schemes. + + \code{\link[grDevices]{col2rgb}} function to express palette + colors represented in the hexadecimal format as RGB triplets (R, G, B). } \author{ J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center diff --git a/man/ReadCodeChunks.Rd b/man/ReadCodeChunks.Rd index 998e614..464b787 100644 --- a/man/ReadCodeChunks.Rd +++ b/man/ReadCodeChunks.Rd @@ -27,6 +27,7 @@ If the source document is \file{.Rnw} or \file{.Rmd} the \code{purl} function is names like \code{unnamed-chunk-i} where \code{i} is the chunk number. } \examples{ +\dontrun{ file <- system.file("misc", "knitr-markdown.Rmd", package = "inlmisc") chunks <- ReadCodeChunks(file) @@ -35,6 +36,7 @@ names(chunks) chunks[["named-chunk-2"]] eval(parse(text = unlist(chunks[c("unnamed-chunk-3", "named-chunk-4")]))) +} } \seealso{ diff --git a/man/SetHinge.Rd b/man/SetHinge.Rd index b706af6..d02dc66 100644 --- a/man/SetHinge.Rd +++ b/man/SetHinge.Rd @@ -10,10 +10,10 @@ SetHinge(x, hinge, scheme = "sunset", alpha = NULL, reverse = FALSE, \arguments{ \item{x}{'numeric' object that can be passed to the \code{\link{range}} function with \code{NA}'s removed. -That is, the user's data range (such as, at sea-level).} +The user's data range.} \item{hinge}{'numeric' number. -Hinge value in data units.} +Hinge value (such as, at sea-level) in data units.} \item{scheme}{'character' vector of length 1 or 2, value is recycled as necessary. Name of color scheme(s). @@ -37,7 +37,7 @@ Values applied separately on either side of the hinge.} \item{stops}{'numeric' vector of length 2. Color stops defined by interval endpoints (between 0 and 1) -and used to select a subset of the color palette.} +and used to select a subset of the color palette(s).} \item{allow_bias}{'logical' flag. Whether to allow bias in the color spacing.} @@ -50,8 +50,8 @@ Returns a 'function' that takes an 'integer' argument The \emph{hinge} indicates a dramatic color change in a palette that is typically located at the midpoint of the data range. An asymmetrical data range can result in an undesired hinge location, -where the location does not necessarily coincide with the break-point in the user's data. -This function is used to specify a hinge location that is appropriate for your data. +a location that does not necessarily coincide with the break-point in the user's data. +This function can be used to specify a hinge location that is appropriate for your data. } \examples{ Pal <- SetHinge(x = c(-3, 7), hinge = 0) diff --git a/man/SummariseBudget.Rd b/man/SummariseBudget.Rd index 84c9c82..a3f4e74 100644 --- a/man/SummariseBudget.Rd +++ b/man/SummariseBudget.Rd @@ -20,7 +20,7 @@ Name of auxiliary variable, a variable of additional values associated with each saved using the \emph{\bold{"AUXILIARY"}} output option.} } \value{ -Returns a 'data.frame' with the following variables: +Returns a 'data.table' with the following variables: \describe{ \item{desc}{description of data type, such as "wells".} \item{kper}{stress period} diff --git a/man/figures/table.pdf b/man/figures/table.pdf index adf4832..104f362 100644 Binary files a/man/figures/table.pdf and b/man/figures/table.pdf differ