Skip to content

Commit

Permalink
Merge pull request #51 from jfisher-usgs/master
Browse files Browse the repository at this point in the history
Merge with upstream
  • Loading branch information
jfisher-usgs authored Oct 27, 2017
2 parents cc02ccd + 4b20aec commit ae34451
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 80 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: inlmisc
Title: Miscellaneous Functions for the USGS INL Project Office
Version: 0.3.4.9000
Version: 0.3.5
Authors@R: person(given=c("Jason", "C."), family="Fisher", role=c("aut", "cre"), email="[email protected]")
Description: A collection of functions for creating high-level graphics,
performing raster-based analysis, processing MODFLOW-based models, etc.
Expand Down Expand Up @@ -35,7 +35,6 @@ Suggests:
httr,
maptools,
parallel,
roxygen2,
testthat
License: CC0
Copyright: This software is in the public domain because it contains materials
Expand Down
8 changes: 6 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# inlmisc 0.3.4.9000
# inlmisc 0.3.5

- ...
- In `PlotMap` function, fix bug introduced by previous fix of raster range calculation.

- Made `AddCertificate` an 'internal' function.

- Add argument checks using **checkmate** package.

# inlmisc 0.3.4

Expand Down
59 changes: 0 additions & 59 deletions R/AddCertificate.R

This file was deleted.

2 changes: 2 additions & 0 deletions R/CreateWebMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

CreateWebMap <- function(..., collapsed=TRUE) {

checkmate::assertLogical(collapsed, len=1, any.missing=FALSE)

# establish layers
basemap <- c("Topo" = "USGSTopo",
"Imagery" = "USGSImageryOnly",
Expand Down
10 changes: 6 additions & 4 deletions R/FormatPval.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
#'

FormatPval <- function(x, digits=max(1, getOption("digits") - 2),
eps=.Machine$double.eps, na.form="NA",
scientific=NA) {
eps=.Machine$double.eps, na.form="NA", scientific=NA) {

x <- as.numeric(x)
scientific <- as.logical(scientific)
checkmate::assertNumeric(x)
checkmate::assertInt(digits, null.ok=TRUE)
checkmate::assertNumber(eps)
checkmate::assertCharacter(na.form, len=1)
checkmate::assertLogical(scientific, len=1)

p <- format(round(x, digits), nsmall=digits, scientific=FALSE)

Expand Down
3 changes: 3 additions & 0 deletions R/GetDaysInMonth.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#'

GetDaysInMonth <- function(x) {

checkmate::assertCharacter(x, pattern="^\\d{6}$", any.missing=FALSE)

d <- as.Date(paste0(x, "28"), format="%Y%m%d")
m <- format(d, format="%m")
for (i in seq_along(d)) {
Expand Down
10 changes: 10 additions & 0 deletions R/Grid2Polygons.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ Grid2Polygons <- function(grd, zcol=1L, level=FALSE, at, cuts=20L,
pretty=FALSE, xlim=NULL, ylim=NULL, zlim=NULL,
ply=NULL) {

# check arguments
checkmate::qassert(zcol, c("s1", "x1"))
checkmate::assertLogical(level, len=1)
if (!missing(at)) checkmate::assertNumeric(at, any.missing=FALSE, min.len=2)
checkmate::assertInt(cuts, lower=1)
checkmate::assertLogical(pretty, len=1)
checkmate::assertNumeric(xlim, len=2, sorted=TRUE, null.ok=TRUE)
checkmate::assertNumeric(ylim, len=2, sorted=TRUE, null.ok=TRUE)
checkmate::assertNumeric(zlim, len=2, sorted=TRUE, null.ok=TRUE)

# check class
what <- c("RasterLayer", "RasterStack", "RasterBrick",
"SpatialPixelsDataFrame", "SpatialGridDataFrame")
Expand Down
4 changes: 4 additions & 0 deletions R/POSIXct2Character.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
#'

POSIXct2Character <- function(x, fmt="%Y-%m-%d %H:%M:%OS3") {

checkmate::assertPOSIXct(x)
checkmate::assertCharacter(fmt, any.missing=FALSE, max.len=1)

pos <- gregexpr("%OS[[:digit:]]+", fmt)[[1]]
if (pos > 0) {
pos <- pos + c(3L, attr(pos, "match.length"))
Expand Down
4 changes: 2 additions & 2 deletions R/PlotMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ PlotMap <- function(r, p=NULL, ..., layer=1, att=NULL, n=NULL, breaks=NULL,
r <- crop(r, extent(e), snap="near")
if (!is.null(p)) p <- crop(p, extent(e), snap="near")

zran <- range(r[])
if (anyNA(zran)) {
if (all(is.na(r[]))) {
n <- 0
} else {
zran <- range(r[], na.rm=TRUE)
default.zl <- if (extend.z) range(pretty(zran, n=6)) else zran
if (raster::is.factor(r)) {
at1 <- raster::levels(r)[[1]][, "ID"]
Expand Down
8 changes: 2 additions & 6 deletions R/ReadCodeChunks.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@

ReadCodeChunks <- function(path) {

if (!file.exists(path)) stop("file not found")
checkmate::assertFileExists(path, extension=c("rnw", "rmd", "r"))

ext <- tools::file_ext(path)
if (tolower(ext) %in% c("rnw", "rmd", "r")) {
src <- readLines(path)
} else {
stop("file extension not recognized")
}
src <- readLines(path)

# extract r code from knitr source documents
if (tolower(ext) %in% c("rnw", "rmd"))
Expand Down
62 changes: 62 additions & 0 deletions R/RecreateLibrary.R
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,65 @@ SavePackageDetails <- function(file="R-packages.tsv", lib=.libPaths(), pkg=NULL)
FUN <- function(i) {system.file(package=i, lib.loc=lib) != ""}
return(vapply(x, FUN, TRUE))
}

#' Add X.509 Certificate
#'
#' This function adds a \href{https://en.wikipedia.org/wiki/X.509}{X.509} certificate
#' to your bundle of certificate authority root certificates (CA bundle).
#' The X.509 certificate is used to authenticate clients and servers.
#' And the CA bundle is a file that contains root and intermediate certificates.
#'
#' @param file 'character'.
#' Path (or a complete URL) to the file containing the X.509 certificate.
#' @param header 'character'.
#' Header line to identify the certificate (optional).
#'
#' @note This function must be used on Windows and requires access to the \pkg{httr} package.
#'
#' @author J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
#'
#' @seealso \code{\link{RecreateLibrary}}
#'
#' @keywords internal
#'
#' @export
#'
#' @examples
#' # Install the U.S. Department of Interior (DOI) certificate (employees only):
#' \dontrun{
#' AddCertificate(file = "http://sslhelp.doi.net/docs/DOIRootCA2.cer",
#' header = "DOI Root CA 2")
#' }
#'

AddCertificate <- function(file, header=NULL) {

checkmate::assertOS("windows")
checkmate::assertCharacter(header, len=1, any.missing=FALSE, null.ok=TRUE)

if (!requireNamespace("httr", quietly=TRUE))
stop("Requires access to the 'httr' package.", call.=FALSE)

if (!file.exists(file) & httr::http_error(file))
stop("Certificate file doesn't exist or access is denied.", call.=FALSE)

certificate <- readLines(file)

bundle <- Sys.getenv("CURL_CA_BUNDLE")
if (bundle == "")
bundle <- system.file("cacert.pem", package="openssl", mustWork=TRUE)
if (!file.exists(bundle))
stop("Can't locate CA bundle file.", call.=FALSE)

if (all(certificate %in% readLines(bundle))) {
message("Certificate has already been added to CA bundle.")
} else {
if (!is.null(header))
header <- c(header, paste(rep("=", nchar(header)), collapse=""))
certificate <- c("", header, certificate)
cat(certificate, file=bundle, sep="\n", append=TRUE)
message("Certificate added to CA bundle:\n ", normalizePath(bundle))
}

invisible(NULL)
}
6 changes: 4 additions & 2 deletions R/SetPolygons.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
#' sp::plot(p, col = "purple", add = TRUE)
#'

SetPolygons <- function(x, y, cmd=c("gIntersection", "gDifference"),
buffer.width=NA) {
SetPolygons <- function(x, y, cmd=c("gIntersection", "gDifference"), buffer.width=NA) {

if (!missing(cmd)) checkmate::assertChoice(cmd, c("gIntersection", "gDifference"))
checkmate::assertNumber(buffer.width, na.ok=TRUE, finite=TRUE)

cmd <- match.arg(cmd)

Expand Down
8 changes: 8 additions & 0 deletions R/ToScientific.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
ToScientific <- function(x, digits=NULL, type=c("latex", "plotmath"),
na=as.character(NA), delimiter="$", scipen=NULL, ...) {

# check arguments
checkmate::assertNumeric(x)
checkmate::assertInt(digits, null.ok=TRUE)
if (!missing(type)) checkmate::assertChoice(type, c("latex", "plotmath"))
checkmate::assertCharacter(na, len=1)
checkmate::assertCharacter(delimiter, len=1)
checkmate::assertInt(scipen, na.ok=TRUE, null.ok=TRUE)

if (missing(type) && methods::hasArg("lab.type"))
type <- list(...)$lab.type # included for backward compatibility
else
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# inlmisc

[![Travis Build Status](https://travis-ci.org/USGS-R/inlmisc.svg?branch=master)](https://travis-ci.org/USGS-R/inlmisc)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/pvcq1jsgabqx61ah?svg=true)](https://ci.appveyor.com/project/jfisher-usgs/inlmisc)
[![Coverage Status](https://coveralls.io/repos/github/USGS-R/inlmisc/badge.svg?branch=master)](https://coveralls.io/github/USGS-R/inlmisc?branch=master)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/inlmisc)](https://CRAN.R-project.org/package=inlmisc)
[![](https://cranlogs.r-pkg.org/badges/inlmisc?color=brightgreen)](https://www.rpackages.io/package/inlmisc)
Expand Down
7 changes: 5 additions & 2 deletions man/AddCertificate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ae34451

Please sign in to comment.