From 6e4555ab82f2c5241b8b1ea922c87b19b3f9a012 Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Fri, 2 Nov 2018 13:06:11 -0700 Subject: [PATCH 01/16] Tidy doc --- R/SetHinge.R | 10 +++++----- man/SetHinge.Rd | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/R/SetHinge.R b/R/SetHinge.R index a2c0fc7..52fd067 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. #' 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) From e77e9b6d33b5201e58040468a8728e6b9cd397c5 Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Fri, 2 Nov 2018 22:13:49 -0700 Subject: [PATCH 02/16] Add permissions section in readme --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/SetHinge.R | 2 +- inst/raw/README.md | 6 ++++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e889b9c..5a2eaaf 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, diff --git a/NEWS.md b/NEWS.md index 2a49013..4c952b0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# inlmisc 0.4.3.9000 +# inlmisc 0.4.4 - Add `SetHinge` function, used to specify a hinge location in a color palette. diff --git a/R/SetHinge.R b/R/SetHinge.R index 52fd067..1b1d8a2 100644 --- a/R/SetHinge.R +++ b/R/SetHinge.R @@ -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/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. From cb9e7bfeac42cfd812e17f4075b09b709781456b Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Fri, 2 Nov 2018 22:51:23 -0700 Subject: [PATCH 03/16] Minor name change --- inst/raw/internal-datasets.R | 4 ++-- man/figures/table.pdf | Bin 72693 -> 72693 bytes 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/raw/internal-datasets.R b/inst/raw/internal-datasets.R index 9a79714..366cfd8 100644 --- a/inst/raw/internal-datasets.R +++ b/inst/raw/internal-datasets.R @@ -24,7 +24,7 @@ MakeSysdata <- function() { tofino vik ") - schemes <- .GetGMTCpt(cite["Wessel"], exclude, diverge) + schemes <- .GetCptGmt(cite["Wessel"], exclude, diverge) schemes[["DEM screen"]] <- list( data = read.csv(strip.white=TRUE, text=" @@ -501,7 +501,7 @@ MakeSysdata <- function() { } -.GetGMTCpt <- function(cite, exclude=NULL, diverge=NULL) { +.GetCptGmt <- function(cite, exclude=NULL, diverge=NULL) { # code adapted from stackoverflow answer by lukeA, accessed October 27, 2018 # at https://stackoverflow.com/questions/25485216 diff --git a/man/figures/table.pdf b/man/figures/table.pdf index adf4832bc10b5d08c664622b16b39c439a7604e6..a69cbb38ca8ab12b1ef231bf2df7f74bde4f84ff 100644 GIT binary patch delta 243 zcmeymo#pFxmJQO3>_$dLCgvu_la&~?VeHKzjK18w=1FEr#s-E4x~Ya1=9Aa)bYh6e zPfq5w;W7#_GO{u;w*s26lGhNK`-Ha$i=HMvdov-gw&G@&Q@iXq>b}~0i zvP?5FGBr;#Gc`6$OR+Rfv@|d@N&yNOnH#1i+SwSGCnuRCC#M;jnx>eT7^aw{7^j-0 UB^sF-7@C_K8W~PEk!Cyy07H2}a{vGU delta 243 zcmeymo#pFxmJQO3?1n~$Mka=qla&~?VeHKzjK18wiHT;$mZ|2cx~T?9Mw8d^bYh6e zPfq5w;W7*{GPE)>u>zX0lGhNK`-Ha$i=HMvdov-gw&G@&Q@iXq>c1ldM zG)qiLHZwC%OH4B{Ni#GxF*CNXur#+cPc$%0HnX!yu}rl{GfOivF*Y;-%9x~>nHm|G USsEFpB_^7t7@1Euk!Cyy0OYbnMgRZ+ From 74ba36709a161b1c3cbbaf5ac76126f365d64b41 Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Sat, 3 Nov 2018 10:50:01 -0700 Subject: [PATCH 04/16] Minor doc changes --- R/GetColors.R | 7 ++++++- man/GetColors.Rd | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) 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/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 From 8f1faeccfa2315f264f4ea35bd2d3843d22af080 Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Sat, 3 Nov 2018 15:15:14 -0700 Subject: [PATCH 05/16] Tidy code --- inst/raw/internal-datasets.R | 34 ++++++++-------------------------- man/figures/table.pdf | Bin 72693 -> 72693 bytes 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/inst/raw/internal-datasets.R b/inst/raw/internal-datasets.R index 366cfd8..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 <- .GetCptGmt(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() { } -.GetCptGmt <- 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/figures/table.pdf b/man/figures/table.pdf index a69cbb38ca8ab12b1ef231bf2df7f74bde4f84ff..104f362f9e44a0bff5094267a4a0e436b2d0ca70 100644 GIT binary patch delta 243 zcmeymo#pFxmJQO3?8b(s29|~vla&~?VeHKzjK18wmPwYz2F58Vx~WEn29wwEbYh6e zPfq5w;W7>}G_^9Yv;vy3lGhNK`-Ha$i=HMvdov-gw&G@&Q@iXq>b}}(D zOfpYSGDu4?N=i&lNlP}iNHa1sGe|ZtOtVNawy?8FF)~WAG)y!zNij`KGBQds14@~j Unj4!NT9}zxT9{5Zk!Cyy0R8bo(*OVf delta 243 zcmeymo#pFxmJQO3>_$dLCgvu_la&~?VeHKzjK18w=1FEr#s-E4x~Ya1=9Aa)bYh6e zPfq5w;W7#_GO{u;w*s26lGhNK`-Ha$i=HMvdov-gw&G@&Q@iXq>b}~0i zvP?5FGBr;#Gc`6$OR+Rfv@|d@N&yNOnH#1i+SwSGCnuRCC#M;jnx>eT7^aw{7^j-0 UB^sF-7@C_K8W~PEk!Cyy07H2}a{vGU From 87da3cc3fa180a9a1d565d43ac73fd80a0e05b50 Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Sun, 4 Nov 2018 08:37:42 -0800 Subject: [PATCH 06/16] Add L back to ReadModflowBinary --- R/ReadModflowBinary.R | 64 +++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/R/ReadModflowBinary.R b/R/ReadModflowBinary.R index 2f68ed7..52887cc 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,25 +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), + ctmp <- readBin(readBin(con, "raw", n=16L, size=1L, endian=endian), "character", n=nval - 1, endian=endian) ctmp <- .TidyDescription(ctmp) } else { ctmp <- NULL } - if (itype %in% c(0, 1)) { + if (itype %in% c(0L, 1L)) { nvalues <- ncol * nrow * nlay d <- .Read3dArray(con, nrow, ncol, nlay, nbytes, endian) for (i in seq_along(d)) { @@ -200,8 +200,8 @@ 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) { @@ -209,7 +209,7 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"), 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) } @@ -221,8 +221,8 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"), 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] @@ -231,11 +231,11 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"), 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, From 194164c8d6b77e0ddd37c401faf6f419b6e5d1da Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Mon, 5 Nov 2018 12:07:26 -0800 Subject: [PATCH 07/16] Rm dplyr --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/ReadModflowBinary.R | 22 +++++++----- R/SummariseBudget.R | 76 ++++++++++++++++++------------------------ man/SummariseBudget.Rd | 2 +- 5 files changed, 48 insertions(+), 55 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5a2eaaf..dde3929 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,7 +12,7 @@ Depends: R (>= 3.4.0) Imports: checkmate, - dplyr, + data.table, GA, graphics, grDevices, diff --git a/NAMESPACE b/NAMESPACE index 3db4ac9..c10a622 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -44,5 +44,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/R/ReadModflowBinary.R b/R/ReadModflowBinary.R index 52887cc..21687ed 100644 --- a/R/ReadModflowBinary.R +++ b/R/ReadModflowBinary.R @@ -185,14 +185,13 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"), if (nval > 100) stop("more than one-hundred varaiables for each cell") if (nval > 1) { ctmp <- readBin(readBin(con, "raw", n=16L, size=1L, endian=endian), - "character", n=nval - 1, endian=endian) + "character", n=nval - 1L, endian=endian) ctmp <- .TidyDescription(ctmp) } else { ctmp <- NULL } if (itype %in% c(0L, 1L)) { - nvalues <- ncol * nrow * nlay 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, @@ -205,7 +204,7 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"), 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)) { @@ -214,9 +213,11 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"), 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) } @@ -228,18 +229,21 @@ ReadModflowBinary <- function(path, data.type=c("array", "flow"), 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 == 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=1L, 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/SummariseBudget.R b/R/SummariseBudget.R index b0c1dcb..6d61eb7 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 @@ -67,7 +69,8 @@ SummariseBudget <- function(budget, desc=NULL, id=NULL) { desc <- unique(budget.desc) } else { 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 +78,41 @@ 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) { - - checkmate::assertList(b) - checkmate::assertCharacter(desc) - checkmate::assertString(id, null.ok=TRUE) - - 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] + dt <- data.table::rbindlist(lapply(desc, function(i) { + data.table::rbindlist(lapply(budget[desc == i], function(x) { + d <- data.frame(desc=x$desc, kper=x$kper, kstp=x$kstp, id=NA, + flow=x$d[, "flow"], delt=x$delt, + pertim=x$pertim, totim=x$totim, + stringsAsFactors=FALSE) + d$id <- if (!is.null(id) && id %in% colnames(x$d)) x$d[, id] else NA + d$flow.dir <- "in" + d$flow.dir[d$flow < 0] <- "out" d })) })) - 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$desc <- as.factor(dt$desc) + dt$flow.dir <- as.factor(dt$flow.dir) + + # due to NSE notes in R CMD check + delt <- flow <- flow.dir <- kper <- kstp <- pertim <- totim <- NULL + + 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)), + by=list(desc, kper, kstp, flow.dir, id)] } 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} From d99878cf40c6b240f718c118cf069b6cba879815 Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Mon, 5 Nov 2018 14:06:07 -0800 Subject: [PATCH 08/16] Rework SummariseBudget --- R/SummariseBudget.R | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/R/SummariseBudget.R b/R/SummariseBudget.R index 6d61eb7..8693e40 100644 --- a/R/SummariseBudget.R +++ b/R/SummariseBudget.R @@ -61,13 +61,12 @@ 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") @@ -86,19 +85,14 @@ SummariseBudget <- function(budget, desc=NULL, id=NULL) { paste(paste0("\"", x, "\""), collapse=", "))) } budget <- budget[is] - desc <- vapply(budget, function(i) i$desc, "") - dt <- data.table::rbindlist(lapply(desc, function(i) { - data.table::rbindlist(lapply(budget[desc == i], function(x) { - d <- data.frame(desc=x$desc, kper=x$kper, kstp=x$kstp, id=NA, - flow=x$d[, "flow"], delt=x$delt, - pertim=x$pertim, totim=x$totim, - stringsAsFactors=FALSE) - d$id <- if (!is.null(id) && id %in% colnames(x$d)) x$d[, id] else NA - d$flow.dir <- "in" - d$flow.dir[d$flow < 0] <- "out" - d - })) + 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, flow.dir="in") + if (!is.null(id) && id %in% colnames(x$d)) d$id <- x$d[, id] + d$flow.dir[d$flow < 0] <- "out" + d })) dt$desc <- as.factor(dt$desc) dt$flow.dir <- as.factor(dt$flow.dir) @@ -114,5 +108,5 @@ SummariseBudget <- function(budget, desc=NULL, id=NULL) { flow.mean = mean(flow), flow.median = stats::median(flow), flow.sd = stats::sd(flow)), - by=list(desc, kper, kstp, flow.dir, id)] + by=list(desc, kper, kstp, flow.dir, id)] } From 9acf0eb481583c08c23ac7baa3d951d52f5db628 Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Mon, 5 Nov 2018 16:44:31 -0800 Subject: [PATCH 09/16] Add 0 back into calc --- R/SummariseBudget.R | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/R/SummariseBudget.R b/R/SummariseBudget.R index 8693e40..4c80820 100644 --- a/R/SummariseBudget.R +++ b/R/SummariseBudget.R @@ -89,24 +89,32 @@ SummariseBudget <- function(budget, desc=NULL, id=NULL) { 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, flow.dir="in") + pertim=x$pertim, totim=x$totim) if (!is.null(id) && id %in% colnames(x$d)) d$id <- x$d[, id] - d$flow.dir[d$flow < 0] <- "out" d })) dt$desc <- as.factor(dt$desc) - dt$flow.dir <- as.factor(dt$flow.dir) + dt$flow.dir <- as.character(NA) # due to NSE notes in R CMD check delt <- flow <- flow.dir <- kper <- kstp <- pertim <- totim <- NULL - 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)), - by=list(desc, kper, kstp, flow.dir, id)] + 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)] + })) + dt_summary$flow.dir <- as.factor(dt_summary$flow.dir) + dt_summary } From bbf6abc2056769528ed06949bc743f4bdd2c62a9 Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Tue, 6 Nov 2018 08:33:11 -0800 Subject: [PATCH 10/16] Do not run example in ReadCodeChunks --- NEWS.md | 4 ++++ R/ReadCodeChunks.R | 2 ++ man/ReadCodeChunks.Rd | 2 ++ 3 files changed, 8 insertions(+) diff --git a/NEWS.md b/NEWS.md index 4c952b0..6bc21be 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # inlmisc 0.4.4 +- 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. - In `PrintTable` function: `d` argument can be of class 'matrix'; and 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/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{ From 541b46eaae61cf6749d26cc958d1e3289f0265ca Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Tue, 6 Nov 2018 09:50:59 -0800 Subject: [PATCH 11/16] Fix path issue with ExportRasterStack --- R/ExportRasterStack.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 From 26a85925295980fefa43980b7f82c97f1f561bcc Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Tue, 6 Nov 2018 21:53:16 -0800 Subject: [PATCH 12/16] Update make doc --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9b42b1c..6b5b1d7 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ PKGSRC := $(shell basename `pwd`) all: docs install check docs: - R -q -e 'devtools::document()';\ + R -q -e 'Rd2roxygen::roxygen_and_build('\''.'\'', build=FALSE, reformat=FALSE)';\ R -q -e 'devtools::clean_dll()';\ build: From 1c9851475ed34fca269276e9323a7a4423681f04 Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Wed, 7 Nov 2018 07:37:33 -0800 Subject: [PATCH 13/16] Minor change --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6b5b1d7..018316d 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ all: docs install check docs: R -q -e 'Rd2roxygen::roxygen_and_build('\''.'\'', build=FALSE, reformat=FALSE)';\ - R -q -e 'devtools::clean_dll()';\ + R -q -e 'pkgbuild::clean_dll()';\ build: cd ..;\ From d593b7fe5d8e30e1703a793f9d252b348700f4be Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Wed, 7 Nov 2018 10:48:17 -0800 Subject: [PATCH 14/16] Add BuildVignettes --- NAMESPACE | 1 + NEWS.md | 2 ++ R/BuildVignettes.R | 49 +++++++++++++++++++++++++++++++++++++++++++ man/BuildVignettes.Rd | 34 ++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 R/BuildVignettes.R create mode 100644 man/BuildVignettes.Rd diff --git a/NAMESPACE b/NAMESPACE index c10a622..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) diff --git a/NEWS.md b/NEWS.md index 6bc21be..1eb4dd8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # 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**. diff --git a/R/BuildVignettes.R b/R/BuildVignettes.R new file mode 100644 index 0000000..98b7e68 --- /dev/null +++ b/R/BuildVignettes.R @@ -0,0 +1,49 @@ +#' Build Package Vignettes +#' +#' Builds package vignettes using the same algorithm that \code{R CMD build} does. +#' +#' @param pkg 'character' string. +#' Package path, defaults to the working directory. +#' @param quiet 'logical' flag. +#' Whether to supress most output. +#' @param gs_quality 'character' string. +#' Quailty to use when compacting 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, gs_quality=NULL) { + + checkmate::assertFileExists(file.path(pkg, "DESCRIPTION")) + checkmate::assertFlag(quiet) + if (!is.null(gs_quality)) + gs_quality <- match.arg(gs_quality, c("none", "printer", "ebook", "screen")) + + tools::buildVignettes(dir=pkg, quiet=quiet, tangle=TRUE) + + v <- tools::pkgVignettes(dir=pkg, output=TRUE, source=TRUE) + if (length(v) == 0) return(invisible(NULL)) + out <- c(unique(unlist(v$sources, use.names=FALSE)), v$outputs) + + doc <- file.path(pkg, "inst/doc") + + dir.create(doc, showWarnings=FALSE, 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/man/BuildVignettes.Rd b/man/BuildVignettes.Rd new file mode 100644 index 0000000..f3bd727 --- /dev/null +++ b/man/BuildVignettes.Rd @@ -0,0 +1,34 @@ +% 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, gs_quality = NULL) +} +\arguments{ +\item{pkg}{'character' string. +Package path, defaults to the working directory.} + +\item{quiet}{'logical' flag. +Whether to supress most output.} + +\item{gs_quality}{'character' string. +Quailty to use when compacting PDF files, see \code{\link[tools]{compactPDF}} function for details.} +} +\description{ +Builds package vignettes using the same algorithm that \code{R CMD build} does. +} +\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} From 06549efc6ac945565dcb34975c21a11e92aa0e3c Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Wed, 7 Nov 2018 12:14:53 -0800 Subject: [PATCH 15/16] Minor changes --- R/BuildVignettes.R | 5 +++-- man/BuildVignettes.Rd | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/R/BuildVignettes.R b/R/BuildVignettes.R index 98b7e68..11ab021 100644 --- a/R/BuildVignettes.R +++ b/R/BuildVignettes.R @@ -1,13 +1,14 @@ #' Build Package Vignettes #' -#' Builds package vignettes using the same algorithm that \code{R CMD build} does. +#' Build package vignettes from their sources. #' #' @param pkg 'character' string. #' Package path, defaults to the working directory. #' @param quiet 'logical' flag. #' Whether to supress most output. #' @param gs_quality 'character' string. -#' Quailty to use when compacting PDF files, see \code{\link[tools]{compactPDF}} function for details. +#' Quailty to use when compacting PDF files, +#' see \code{\link[tools]{compactPDF}} function for details. #' #' @author J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center #' diff --git a/man/BuildVignettes.Rd b/man/BuildVignettes.Rd index f3bd727..2d4d66f 100644 --- a/man/BuildVignettes.Rd +++ b/man/BuildVignettes.Rd @@ -14,10 +14,11 @@ Package path, defaults to the working directory.} Whether to supress most output.} \item{gs_quality}{'character' string. -Quailty to use when compacting PDF files, see \code{\link[tools]{compactPDF}} function for details.} +Quailty to use when compacting PDF files, +see \code{\link[tools]{compactPDF}} function for details.} } \description{ -Builds package vignettes using the same algorithm that \code{R CMD build} does. +Build package vignettes from their sources. } \examples{ \dontrun{ From 36aeec312dc832e4cd235a5184860ad1c500fc97 Mon Sep 17 00:00:00 2001 From: Jason Fisher Date: Wed, 7 Nov 2018 14:21:23 -0800 Subject: [PATCH 16/16] Add clean arg to BuildVignettes --- R/BuildVignettes.R | 17 ++++++++++------- man/BuildVignettes.Rd | 12 ++++++++---- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/R/BuildVignettes.R b/R/BuildVignettes.R index 11ab021..8840fb9 100644 --- a/R/BuildVignettes.R +++ b/R/BuildVignettes.R @@ -1,13 +1,15 @@ #' Build Package Vignettes #' -#' Build package vignettes from their sources. +#' Build package vignettes from their sources and place in the \code{/inst/doc} folder. #' #' @param pkg 'character' string. -#' Package path, defaults to the working directory. +#' 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. -#' Quailty to use when compacting PDF files, +#' 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 @@ -24,22 +26,23 @@ #' } #' -BuildVignettes <- function(pkg=".", quiet=TRUE, gs_quality=NULL) { +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, tangle=TRUE) + 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(unique(unlist(v$sources, use.names=FALSE)), v$outputs) + out <- c(v$outputs, unique(unlist(v$sources, use.names=FALSE))) doc <- file.path(pkg, "inst/doc") - dir.create(doc, showWarnings=FALSE, recursive=TRUE) + dir.create(doc, showWarnings=!quiet, recursive=TRUE) file.copy(c(v$docs, out), doc, overwrite=TRUE) file.remove(out) diff --git a/man/BuildVignettes.Rd b/man/BuildVignettes.Rd index 2d4d66f..e3105aa 100644 --- a/man/BuildVignettes.Rd +++ b/man/BuildVignettes.Rd @@ -4,21 +4,25 @@ \alias{BuildVignettes} \title{Build Package Vignettes} \usage{ -BuildVignettes(pkg = ".", quiet = TRUE, gs_quality = NULL) +BuildVignettes(pkg = ".", quiet = TRUE, clean = TRUE, + gs_quality = NULL) } \arguments{ \item{pkg}{'character' string. -Package path, defaults to the working directory.} +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. -Quailty to use when compacting PDF files, +Quality of compacted PDF files, see \code{\link[tools]{compactPDF}} function for details.} } \description{ -Build package vignettes from their sources. +Build package vignettes from their sources and place in the \code{/inst/doc} folder. } \examples{ \dontrun{