Skip to content

Commit

Permalink
fix: table_updateColumn() now ignores unknown locationIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathancallahan committed Jul 14, 2022
1 parent 70b39e8 commit a4dff9e
Show file tree
Hide file tree
Showing 63 changed files with 458 additions and 180 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Package
Package: MazamaLocationUtils
Version: 0.3.6
Version: 0.3.7
Title: Manage Spatial Metadata for Known Locations
Authors@R: c(
person("Jonathan", "Callahan", email="[email protected]", role=c("aut","cre")),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# MazamaLocationUtils 0.3.7

* Updated `table_updateColumn()` to ignore incoming `locationIDs` that are not
found in the `locationTbl`.

# MazamaLocationUtils 0.3.6

* Added `table_getDistanceFromTarget()` and edited the description of other
Expand Down
29 changes: 23 additions & 6 deletions R/table_updateColumn.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@

#' @title Update a column of metadata in a table
#' @description For matching \code{locationID}, records the associated
#' \code{locationData} is used to replace any existing value in \code{columnName}.
#' \code{NA} values in \code{locationID} will be ignored.
#'
#' @description Updates records in a location table. Records are identified
#' by \code{locationID} and the data found in \code{locationData} is used to
#' replace any existing value in the \code{columnName} column.
#' \code{locationID} and \code{locationData} must be of the same length.
#' Any \code{NA} values in \code{locationID} will be ignored.
#'
#' If \code{columnName} is not a named column within \code{locationTbl}, a new
#' column will be created.
#'
#' @param locationTbl Tibble of known locations.
#' @param columnName Name to use for the new column.
#' @param columnName Name of an existing/new column in \code{locationTbl} whose data
#' will be updated/created.
#' @param locationID Vector of \code{locationID} strings.
#' @param locationData Vector of data to used at matching records.
#' @param locationData Vector of data to be inserted at records identified by
#' \code{locationID}.
#' @param verbose Logical controlling the generation of progress messages.
#' @return Updated tibble of known locations.
#' @examples
Expand Down Expand Up @@ -47,6 +56,7 @@
#' @export
#' @importFrom MazamaCoreUtils stopIfNull
#' @importFrom dplyr bind_rows

table_updateColumn <- function(
locationTbl = NULL,
columnName = NULL,
Expand Down Expand Up @@ -86,8 +96,15 @@ table_updateColumn <- function(
locationTbl <- table_addColumn(locationTbl, columnName)

if ( !is.null(locationData) ) {
# Get the indices to be updated
# Get the record indices to be updated
recordIndex <- table_getRecordIndex(locationTbl, locationID)

# Remove incoming locationData not associated with any record
mask <- !is.na(recordIndex)
recordIndex <- recordIndex[mask]
locationData <- locationData[mask]

# Updated record data
locationTbl[[columnName]][recordIndex] <- locationData
}

Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

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

125 changes: 93 additions & 32 deletions docs/articles/MazamaLocationUtils.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});
2 changes: 1 addition & 1 deletion docs/articles/index.html

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

2 changes: 1 addition & 1 deletion docs/authors.html

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

99 changes: 77 additions & 22 deletions docs/index.html

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

Loading

0 comments on commit a4dff9e

Please sign in to comment.