Skip to content

Commit

Permalink
Merge pull request #133 from jfisher-usgs/master
Browse files Browse the repository at this point in the history
Merge with upstream
  • Loading branch information
jfisher-usgs authored Jul 21, 2020
2 parents 18bd9e6 + 993fee9 commit 1177de6
Show file tree
Hide file tree
Showing 14 changed files with 286 additions and 86 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
^data-raw$
^README\.Rmd$
^README\.html$
^code.json$
^DISCLAIMER.md$
^LICENSE.md$
4 changes: 2 additions & 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.4.9
Version: 0.5.0
Authors@R: person(given=c("Jason", "C."), family="Fisher", role=c("aut", "cre"), email="[email protected]", 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,
Expand Down Expand Up @@ -54,4 +54,4 @@ BugReports: https://github.com/USGS-R/inlmisc/issues
Encoding: UTF-8
LazyData: true
LazyDataCompression: xz
RoxygenNote: 7.0.2
RoxygenNote: 7.1.1
12 changes: 12 additions & 0 deletions DISCLAIMER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Disclaimer
----------

This software has been approved for release by the U.S. Geological Survey
(USGS). Although the software has been subjected to rigorous review, the USGS
reserves the right to update the software as needed pursuant to further analysis
and review. No warranty, expressed or implied, is made by the USGS or the U.S.
Government as to the functionality of the software and related material nor
shall the fact of release constitute any such warranty. Furthermore, the
software is released on condition that neither the USGS nor the U.S. Government
shall be held liable for any damages resulting from its authorized or
unauthorized use.
41 changes: 22 additions & 19 deletions LICENSE.note → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
U.S. Geological Survey Software User Rights Notice
LICENSE
=======

Creative Commons (CC0) license
------------------------------

The code within this repository is distributed under the
**Creative Commons (CCO) license** and further details concerning this license and USGS
coded so associated can be found at
https://www.usgs.gov/products/software/software-management/distribution-usgs-code
on July 7, 2020.

Software User Rights Notice
---------------------------

**U.S.Geological Survey Software User Rights Notice** copied from
https://water.usgs.gov/software/help/notice/ on July 7, 2020.
Please check webpage for updates.

Software and related material (data and (or) documentation), contained in or
furnished in connection with a software distribution, are made available by the
Expand All @@ -9,10 +26,10 @@ documentation, subject to the following restrictions and understandings.

If you distribute copies or modifications of the software and related material,
make sure the recipients receive a copy of this notice and receive or can get a
copy of the original distribution. If the software and (or) related material
are modified and distributed, it must be made clear that the recipients do not
have the original and they must be informed of the extent of the modifications.
For example, modified files must include a prominent notice stating the
copy of the original distribution. If the software and (or) related material are
modified and distributed, it must be made clear that the recipients do not have
the original and they must be informed of the extent of the modifications. For
example, modified files must include a prominent notice stating the
modifications made, the author of the modifications, and the date the
modifications were made. This restriction is necessary to guard against problems
introduced in the software by others, reflecting negatively on the reputation of
Expand Down Expand Up @@ -42,17 +59,3 @@ updates, revisions, new versions or "bug fixes".
The user assumes all risk for any damages whatsoever resulting from loss of use,
data, or profits arising in connection with the access, use, quality, or
performance of this software.

R and other package dependencies have more restrictive licenses.

Color schemes in the inlmisc package are included with the permission of
the author, either explicitly or where the license under which they were
distributed allows it. For instance, the Generic Mapping Tools (GMT) color
palette tables are distributed under the GNU Lesser General Public License
(LGPL), version 3 or later. Refer to the license notice included with the source
files in raw/cpt/. Google's turbo colormap look-up table is distributed under
the Apache License, version 2.0.

The inlmisc package includes the leaflet-search software, a leaflet plugin
distributed under the MIT license. Refer to the license notice included with
the source files in htmlwidgets/plugins/leaflet-search/.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ tables: install
rm -r ../man/figures
mv -f figures ../man/
.PHONY: tables

readme:
R -q -e 'rmarkdown::render('\''README.Rmd'\'')'
.PHONY: readme
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# inlmisc 0.5.0

- Add top-level *README.Rmd* file.

- Remove *LICENSE.note* file from package, and replace witha repo-only *LICENSE.md* file.

- Add *DISCLAIMER.md* file.

- In LaTeX preamble, include new solution for printing fancy header on all pages.

- In `AddInsetMap`, add `feature` argument, used to add one or more spatial features to the inset map.

# inlmisc 0.4.9

- In LaTeX preamble, omit group separators in the decimal part when using **siunitx** package.
Expand Down
46 changes: 31 additions & 15 deletions R/AddInsetMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@
#' Width of the inset map in inches.
#' @param e 'numeric' vector of length 4.
#' Extent of the smaller axis-aligned rectangle (relative to the larger map polygon).
#' Defaults to the user coordinate extent of the main plot region, see \code{par("usr")}.
#' Defaults to the user coordinate extent of the main plot region.
#' @param bty 'character' string.
#' Type of box to be drawn about the inset map.
#' A value of \code{"o"} (the default) results in a box and a value of \code{"n"} suppresses the box.
#' @param feature 'list'.
#' One or more spatial objects, along with style arguments, to add to the inset map.
#' Each list element is a 'list'-class object that contains the following components:
#' the first component is the name of the plotting function;
#' the second component is the object to be plotted; and
#' the remaining components are reserved for arguments to be passed to the function.
#'
#' @return Invisible \code{NULL}
#'
Expand All @@ -44,16 +50,17 @@
#' PlotMap(county, xlim = ext[1:2], ylim = ext[3:4],
#' dms.tick = TRUE)
#' sp::plot(county, add = TRUE)
#' inlmisc::AddInsetMap(county, width = 2,
#' main.label = list("IDAHO", "adj" = c(0, -10)),
#' sub.label = list("Map area", "adj" = c(0, -4)),
#' loc = "topright")
#' AddInsetMap(county, width = 2,
#' main.label = list("IDAHO", "adj" = c(0, -10)),
#' sub.label = list("Map area", "adj" = c(0, -4)),
#' loc = "topright")
#'

AddInsetMap <- function(p, col=c("#D8D8D8", "#BFA76F"),
main.label=list("label"=NA, "adj"=NULL),
sub.label=list("label"=NA, "adj"=NULL), loc="topright",
inset=0.02, width=NULL, e=NULL, bty=c("o", "n")) {
inset=0.02, width=NULL, e=graphics::par("usr"),
bty=c("o", "n"), feature=NULL) {

checkmate::assertClass(p, "SpatialPolygons")
checkmate::assertCharacter(col, any.missing=FALSE, len=2)
Expand All @@ -63,18 +70,23 @@ AddInsetMap <- function(p, col=c("#D8D8D8", "#BFA76F"),
checkmate::assertNumber(width, finite=TRUE, null.ok=TRUE)
checkmate::assertNumeric(e, finite=TRUE, len=4, null.ok=TRUE)
bty <- match.arg(bty)
checkmate::assertList(feature, types="list", any.missing=FALSE, null.ok=TRUE)

op <- graphics::par(no.readonly=TRUE)
on.exit(graphics::par(op))

usr <- graphics::par("usr")

if (is.null(e)) e <- usr
crds <- cbind(c(e[1:2], e[2:1], e[1]), c(rep(e[3], 2), rep(e[4], 2), e[3]))
b <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(crds)), "bbox")), proj4string=raster::crs(p))
if (length(rgeos::gIntersection(p, b, checkValidity=2L)) == 0)
if (is.null(e)) {
ext <- raster::extent(p)
} else {
crds <- cbind(c(e[1:2], e[2:1], e[1]), c(rep(e[3], 2), rep(e[4], 2), e[3]))
b <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(crds)), "bbox")),
proj4string=raster::crs(p))
if (length(rgeos::gIntersection(p, b, checkValidity=2L)) == 0)
stop("user coordinates of the plotting region do not intersect polygon")
ext <- raster::extent(rgeos::gUnion(p, b, checkValidity=2L))
ext <- raster::extent(rgeos::gUnion(p, b, checkValidity=2L))
}

if (is.null(width)) {
dx <- 0.2 * diff(usr[1:2])
Expand All @@ -93,15 +105,19 @@ AddInsetMap <- function(p, col=c("#D8D8D8", "#BFA76F"),
ylim <- range(ext[3:4])
graphics::plot.window(xlim=xlim, ylim=ylim)

sp::plot(p, col=col[1], border=NA, lwd=0.25, add=TRUE)
sp::plot(b, col=col[2], border="#090909", lwd=0.25, add=TRUE)
sp::plot(p, col=NA, border="#090909", lwd=0.25, add=TRUE)
sp::plot(p, col=col[1], border=NA, lwd=0.25, add=TRUE)
sp::plot(p, col=NA, border="#090909", lwd=0.25, add=TRUE)

if (!is.null(e))
sp::plot(b, col=col[2], border="#090909", lwd=0.25, add=TRUE)

for (item in feature) do.call(item[[1]], item[-1])

if (!is.na(main.label[[1]])) {
x <- sp::coordinates(rgeos::gUnaryUnion(p, checkValidity=2L))[1, ]
graphics::text(x[1], x[2], labels=main.label[[1]], adj=main.label$adj, cex=0.7, font=2)
}
if (!is.na(sub.label[[1]])) {
if (!is.na(sub.label[[1]]) && !is.null(e)) {
x <- sp::coordinates(rgeos::gUnaryUnion(b, checkValidity=2L))[1, ]
graphics::text(x[1], x[2], labels=sub.label[[1]], adj=sub.label$adj, cex=0.6)
}
Expand Down
1 change: 0 additions & 1 deletion R/usgs_article.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#'
#' Format for creating a U.S. Geological Survey (USGS) article.
#'
#' @inheritParams rmarkdown::pdf_document
#' @param ... Arguments passed to the \code{\link[rmarkdown]{pdf_document}} function.
#'
#' @return R Markdown output format to pass to \code{\link[rmarkdown]{render}}
Expand Down
81 changes: 81 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
output:
md_document
---

inlmisc
=======

[![Travis Build Status](https://travis-ci.org/USGS-R/inlmisc.svg?branch=master)](https://travis-ci.org/USGS-R/inlmisc)
[![CRAN Version](https://www.r-pkg.org/badges/version/inlmisc)](https://CRAN.R-project.org/package=inlmisc)
[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/inlmisc?color=brightgreen)](https://CRAN.R-project.org/package=inlmisc)
[![Dependencies](https://tinyverse.netlify.com/badge/inlmisc)](https://CRAN.R-project.org/package=inlmisc)
[![Coverage Status](https://coveralls.io/repos/github/USGS-R/inlmisc/badge.svg?branch=master)](https://coveralls.io/github/USGS-R/inlmisc?branch=master)
[![USGS Category](https://img.shields.io/badge/USGS-Support-yellow.svg)](https://owi.usgs.gov/R/packages.html#support)

Description
-----------

The [R](https://www.r-project.org/) package **inlmisc** is a collection of functions for creating high-level graphics,
performing raster-based analysis, processing [MODFLOW](https://www.usgs.gov/mission-areas/water-resources/science/modflow-and-related-programs "USGS's modular hydrologic model")-based models,
selecting subsets using a genetic algorithm, creating interactive web maps, accessing color palettes, etc.
Used to support packages and scripts written by researchers at the U.S. Geological Survey (USGS)
Idaho National Laboratory (INL) [Project Office](https://www.usgs.gov/centers/id-water/science/idaho-national-laboratory-project-office "USGS INL Project Office").

Installation
------------

The current release is available on [CRAN](https://CRAN.R-project.org/package=inlmisc "The Comprehensive R Archive Network"),
which you can install using the following command:

```r
install.packages("inlmisc", dependencies = TRUE)
```

To install the development version, you need to clone the repository and build from source, or run:

```r
if (!requireNamespace("remotes")) install.packages("remotes")
remotes::install_github("USGS-R/inlmisc", dependencies = TRUE)
```

Usage
-----

Examples are given in the package help pages.
To access this documentation, run:

```r
library("inlmisc")
help(package = "inlmisc")
```

Author
------

Jason C. Fisher (ORCID iD [0000-0001-9032-8912](http://orcid.org/0000-0001-9032-8912))

Suggested citation
------------------

```{r "citation", echo=FALSE, results="asis"}
cit <- utils::citation(package="inlmisc")
print(cit, bibtex=FALSE)
```

Contributing
------------

Please submit bug reports, suggestions, and pull requests to the
[issues tracker](https://github.com/USGS-R/inlmisc/issues).

Package support
---------------

The Idaho National Laboratory Project Office of the USGS supports the development and maintenance of inlmisc.
Resources are available primarily for maintenance and responding to user questions.
Priorities on the development of new features are determined by the inlmisc development team.

```{r "support", echo=FALSE, results="asis"}
cat(readLines("DISCLAIMER.md"), sep="\n")
```
Loading

0 comments on commit 1177de6

Please sign in to comment.