diff --git a/DESCRIPTION b/DESCRIPTION index ad4f86f..664c77d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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="jonathan.s.callahan@gmail.com", role=c("aut","cre")), diff --git a/NEWS.md b/NEWS.md index 35cb155..5f630eb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/table_updateColumn.R b/R/table_updateColumn.R index 65deed6..32fc2c8 100644 --- a/R/table_updateColumn.R +++ b/R/table_updateColumn.R @@ -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 @@ -47,6 +56,7 @@ #' @export #' @importFrom MazamaCoreUtils stopIfNull #' @importFrom dplyr bind_rows + table_updateColumn <- function( locationTbl = NULL, columnName = NULL, @@ -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 } diff --git a/docs/404.html b/docs/404.html index 26c5010..d3600ec 100644 --- a/docs/404.html +++ b/docs/404.html @@ -71,7 +71,7 @@
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 2a96cf1..b3a15d1 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -71,7 +71,7 @@ diff --git a/docs/articles/MazamaLocationUtils.html b/docs/articles/MazamaLocationUtils.html index 7d5d137..c37ac80 100644 --- a/docs/articles/MazamaLocationUtils.html +++ b/docs/articles/MazamaLocationUtils.html @@ -31,7 +31,7 @@ @@ -70,7 +70,7 @@ -This package is intended for use in data management activities associated with fixed locations in space. The motivating fields include air and water quality monitoring where fixed sensors report at regular time intervals.
-When working with environmental monitoring time series, one of the first things you have to do is create unique identifiers for each individual time series. In an ideal world, each environmental time series would have both a locationID
and a deviceID
that uniquely identify the specific instrument making measurements and the physical location where measurements are made. A unique timeseriesID
could be produced as locationID_deviceID
. Metadata associated with each timeseriesID
would contain basic information needed for downstream analysis including at least:
This package is intended for use in data management activities +associated with fixed locations in space. The motivating fields include +air and water quality monitoring where fixed sensors report at regular +time intervals.
+When working with environmental monitoring time series, one of the
+first things you have to do is create unique identifiers for each
+individual time series. In an ideal world, each environmental time
+series would have both a locationID
and a
+deviceID
that uniquely identify the specific instrument
+making measurements and the physical location where measurements are
+made. A unique timeseriesID
could be produced as
+locationID_deviceID
. Metadata associated with each
+timeseriesID
would contain basic information needed for
+downstream analysis including at least:
timeseriesID, locationID, deviceID, longitude, latitude, ...
deviceID
.locationID
.deviceID
.locationID
.longitude, latitude
.data
table with timeseriesID
column names.data
table with timeseriesID
column
+names.Unfortunately, we are rarely supplied with a truly unique and truly spatial locationID
. Instead we often use deviceID
or an associated non-spatial identifier as a stand-in for locationID
.
Unfortunately, we are rarely supplied with a truly unique and truly
+spatial locationID
. Instead we often use
+deviceID
or an associated non-spatial identifier as a
+stand-in for locationID
.
Complications we have seen include:
locationID
.locationID
.locationID
.locationID
.A solution to all these problems is possible if we store spatial metadata in simple tables in a standard directory. These tables will be referred to as collections. Location lookups can be performed with geodesic distance calculations where a longitude-latitude pair is assigned to a pre-existing known location if it is within distanceThreshold
meters of that location. These lookups will be extremely fast.
If no previously known location is found, the relatively slow (seconds) creation of a new known location metadata record can be performed and then added to the growing collection.
-For collections of stationary environmental monitors that only number in the thousands, this entire collection can be stored as either a .rda
or .csv
file and will be under a megabyte in size making it fast to load. This small size also makes it possible to store multiple known locations files, each created with different locations and different distance thresholds to address the needs of different scientific studies.
A solution to all these problems is possible if we store spatial
+metadata in simple tables in a standard directory. These tables will be
+referred to as collections. Location lookups can be performed
+with geodesic distance calculations where a longitude-latitude pair is
+assigned to a pre-existing known location if it is within
+distanceThreshold
meters of that location. These lookups
+will be extremely fast.
If no previously known location is found, the relatively +slow (seconds) creation of a new known location metadata record +can be performed and then added to the growing collection.
+For collections of stationary environmental monitors that only number
+in the thousands, this entire collection can be stored as
+either a .rda
or .csv
file and will be under a
+megabyte in size making it fast to load. This small size also makes it
+possible to store multiple known locations files, each created
+with different locations and different distance thresholds to address
+the needs of different scientific studies.
The package comes with some example known locations tables.
-Lets take some metadata we have for air quality monitors in Washington state and create a known locations table for them.
+The package comes with some example known locations +tables.
+Lets take some metadata we have for air quality monitors in +Washington state and create a known locations table for +them.
@@ -133,7 +179,8 @@We can create a known locations table for them with a minimum 500 meter separation between distinct locations:
+We can create a known locations table for them with a +minimum 500 meter separation between distinct locations:
library(MazamaLocationUtils)
@@ -144,7 +191,8 @@
wa_monitors_500 <-
table_initialize() %>%
table_addLocation(wa$longitude, wa$latitude, distanceThreshold = 500)
Right now, our known locations table contains only automatically generated spatial metadata:
+Right now, our known locations table contains only +automatically generated spatial metadata:
dplyr::glimpse(wa_monitors_500)
## Rows: 68
@@ -166,8 +214,12 @@
Merging external metadata
-Perhaps we would like to import some of the original metadata into our new table. This is a very common use case where non-spatial metadata like site name or agency responsible for a monitor can be added.
-Just to make it interesting, let’s assume that our known locations table is already large and we are only providing additional metadata for a subset of the records.
+Perhaps we would like to import some of the original metadata into
+our new table. This is a very common use case where non-spatial metadata
+like site name or agency responsible for a monitor can be added.
+Just to make it interesting, let’s assume that our known
+locations table is already large and we are only providing
+additional metadata for a subset of the records.
# Use a subset of the wa metadata
wa_indices <- seq(5,65,5)
@@ -212,12 +264,15 @@
## 11 Walla Walla Walla Walla-12th St
## 12 Chehalis Chehalis-Market Blvd
## 13 Tacoma Tacoma-S 36th St
-Very nice. We have added siteName
to our known locations table for a more detailed description of each monitors’ location.
+Very nice. We have added siteName
to our known locations
+table for a more detailed description of each monitors’ location.
Finding known locations
-The whole point of a known locations table is to speed up access to spatial and other metadata. Here’s how we can use it with a set of longitudes and latitudes that are not currently in our table.
+The whole point of a known locations table is to speed up access to
+spatial and other metadata. Here’s how we can use it with a set of
+longitudes and latitudes that are not currently in our table.
# Create new locations near our known locations
lons <- jitter(wa_sub$longitude)
@@ -239,10 +294,10 @@
latitude = lats,
distanceThreshold = 500
) %>% dplyr::pull(city)
-## [1] "Okanogan County" NA NA NA
-## [5] "Anacortes" "Quincy" "Tulalip Bay" "Shelton"
-## [9] NA NA "Walla Walla" NA
-## [13] NA
+## [1] "Okanogan County" NA "Tacoma" "Auburn"
+## [5] NA NA "Tulalip Bay" NA
+## [9] NA "Wenatchee" NA NA
+## [13] "Tacoma"
# How about 5000 meters?
table_getNearestLocation(
@@ -260,7 +315,9 @@
Standard Setup
-Before using MazamaLocationUtils you must first install MazamaSpatialUtils and then install core spatial data with:
+Before using MazamaLocationUtils you must first
+install MazamaSpatialUtils and then install core
+spatial data with:
library(MazamaSpatialUtils)
setSpatialDataDir("~/Data/Spatial")
@@ -275,7 +332,8 @@
library(MazamaLocationUtils)
mazama_initialize()
setLocationDataDir("~/Data/KnownLocations")
-mazama_initialize()
assumes spatial data are installed in the standard location and is just a wrapper for:
+mazama_initialize()
assumes spatial data are installed
+in the standard location and is just a wrapper for:
MazamaSpatialUtils::setSpatialDataDir("~/Data/Spatial")
@@ -283,7 +341,10 @@
MazamaSpatialUtils::loadSpatialData("OSMTimezones.rda")
MazamaSpatialUtils::loadSpatialData("NaturalEarthAdm1.rda")
MazamaSpatialUtils::loadSpatialData("USCensusCounties.rda")
-Every time you table_save()
your location table, a backup will be created so you can experiment without losing your work. File sizes are pretty tiny so you don’t have to worry about filling up your disk.
+Every time you table_save()
your location table, a
+backup will be created so you can experiment without losing your work.
+File sizes are pretty tiny so you don’t have to worry about filling up
+your disk.
Best wishes for well organized spatial metadata!
diff --git a/docs/articles/MazamaLocationUtils_files/header-attrs-2.14/header-attrs.js b/docs/articles/MazamaLocationUtils_files/header-attrs-2.14/header-attrs.js
new file mode 100644
index 0000000..dd57d92
--- /dev/null
+++ b/docs/articles/MazamaLocationUtils_files/header-attrs-2.14/header-attrs.js
@@ -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);
+ }
+});
diff --git a/docs/articles/index.html b/docs/articles/index.html
index 336c7ee..408eb1d 100644
--- a/docs/articles/index.html
+++ b/docs/articles/index.html
@@ -71,7 +71,7 @@
diff --git a/docs/authors.html b/docs/authors.html
index 9eb7563..523e42d 100644
--- a/docs/authors.html
+++ b/docs/authors.html
@@ -71,7 +71,7 @@
diff --git a/docs/index.html b/docs/index.html
index 1a8dbbb..1dee99d 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -34,7 +34,7 @@
@@ -87,46 +87,101 @@
Background
-This package is intended for use in data management activities associated with fixed locations in space. The motivating fields include air and water quality monitoring where fixed sensors report at regular time intervals.
-When working with environmental monitoring time series, one of the first things you have to do is create unique identifiers for each individual time series. In an ideal world, each environmental time series would have both a locationID
and a deviceID
that uniquely identify the specific instrument making measurements and the physical location where measurements are made. A unique timeseriesID
could be produced as locationID_deviceID
. Metadata associated with each timeseriesID
would contain basic information needed for downstream analysis including at least:
+This package is intended for use in data management activities
+associated with fixed locations in space. The motivating fields include
+air and water quality monitoring where fixed sensors report at regular
+time intervals.
+When working with environmental monitoring time series, one of the
+first things you have to do is create unique identifiers for each
+individual time series. In an ideal world, each environmental time
+series would have both a locationID
and a
+deviceID
that uniquely identify the specific instrument
+making measurements and the physical location where measurements are
+made. A unique timeseriesID
could be produced as
+locationID_deviceID
. Metadata associated with each
+timeseriesID
would contain basic information needed for
+downstream analysis including at least:
timeseriesID, locationID, deviceID, longitude, latitude, ...
-- An extended time series for a mobile sensor would group by
deviceID
.
-- Multiple sensors placed at a single location could be be grouped by
locationID
.
+- An extended time series for a mobile sensor would group by
+
deviceID
.
+- Multiple sensors placed at a single location could be be grouped by
+
locationID
.
- Maps would be created using
longitude, latitude
.
-- Time series measurements would be accessed from a secondary
data
table with timeseriesID
column names.
+- Time series measurements would be accessed from a secondary
+
data
table with timeseriesID
column
+names.
-Unfortunately, we are rarely supplied with a truly unique and truly spatial locationID
. Instead we often use deviceID
or an associated non-spatial identifier as a stand-in for locationID
.
+Unfortunately, we are rarely supplied with a truly unique and truly
+spatial locationID
. Instead we often use
+deviceID
or an associated non-spatial identifier as a
+stand-in for locationID
.
Complications we have seen include:
-- GPS-reported longitude and latitude can have jitter in the fourth or fifth decimal place making it challenging to use them to create a unique
locationID
.
-- Sensors are sometimes repositioned in what the scientist considers the “same location”.
-- Data from a single sensor goes through different processing pipelines using different identifiers and is later brought together as two separate timeseries.
-- The spatial scale of what constitutes a “single location” depends on the instrumentation and scientific question being asked.
-- Deriving location-based metadata from spatial datasets is computationally intensive unless saved and identified with a unique
locationID
.
-- Automated searches for spatial metadata occasionally produce incorrect results because of the non-infinite resolution of spatial datasets and must be corrected by hand.
+- GPS-reported longitude and latitude can have jitter in the
+fourth or fifth decimal place making it challenging to use them to
+create a unique
locationID
.
+- Sensors are sometimes repositioned in what the scientist
+considers the “same location”.
+- Data from a single sensor goes through different processing
+pipelines using different identifiers and is later brought together as
+two separate timeseries.
+- The spatial scale of what constitutes a “single location” depends on
+the instrumentation and scientific question being asked.
+- Deriving location-based metadata from spatial datasets is
+computationally intensive unless saved and identified with a unique
+
locationID
.
+- Automated searches for spatial metadata occasionally produce
+incorrect results because of the non-infinite resolution of spatial
+datasets and must be corrected by hand.
A Solution
-A solution to all these problems is possible if we store spatial metadata in simple tables in a standard directory. These tables will be referred to as collections. Location lookups can be performed with geodesic distance calculations where a longitude-latitude pair is assigned to a pre-existing known location if it is within distanceThreshold
meters of that location. These lookups will be extremely fast.
-If no previously known location is found, the relatively slow (seconds) creation of a new known location metadata record can be performed and then added to the growing collection.
-For collections of stationary environmental monitors that only number in the thousands, this entire collection can be stored as either a .rda
or .csv
file and will be under a megabyte in size making it fast to load. This small size also makes it possible to save multiple known locations files, each created with different locations and different distance thresholds to address the needs of different scientific studies.
+A solution to all these problems is possible if we store spatial
+metadata in simple tables in a standard directory. These tables will be
+referred to as collections. Location lookups can be performed
+with geodesic distance calculations where a longitude-latitude pair is
+assigned to a pre-existing known location if it is within
+distanceThreshold
meters of that location. These lookups
+will be extremely fast.
+If no previously known location is found, the relatively
+slow (seconds) creation of a new known location metadata record
+can be performed and then added to the growing collection.
+For collections of stationary environmental monitors that only number
+in the thousands, this entire collection can be stored as
+either a .rda
or .csv
file and will be under a
+megabyte in size making it fast to load. This small size also makes it
+possible to save multiple known locations files, each created
+with different locations and different distance thresholds to address
+the needs of different scientific studies.
Immediate Advantages
-Working in this manner will solve the problems initially mentioned but also provides further useful functionality:
+Working in this manner will solve the problems initially mentioned
+but also provides further useful functionality:
-- Administrators can correct entries in an individual collection. (e.g. locations in river bends that even high resolution spatial datasets mis-assign)
-- Additional, non-automatable metadata can be added to a collection. (e.g. commonly used location names within a community of practice)
-- Different field campaigns can maintain separate collections.
+- Administrators can correct entries in an individual
+collection. (e.g. locations in river bends that even
+high resolution spatial datasets mis-assign)
+- Additional, non-automatable metadata can be added to a
+collection. (e.g. commonly used location names within
+a community of practice)
+- Different field campaigns can maintain separate
+collections.
-
-
.csv
or .rda
versions of well populated tables can be downloaded from a URL and used locally, giving scientists and analysts working with known locations instant access to location-specific spatial metadata data that otherwise requires special software and skills, large datasets and many compute cycles to generate.
+.csv
or .rda
versions of well populated
+tables can be downloaded from a URL and used locally, giving scientists
+and analysts working with known locations instant access to
+location-specific spatial metadata data that otherwise requires special
+software and skills, large datasets and many compute cycles to
+generate.
-This project is supported with funding from the US Forest Service.
+This project is supported with funding from the US Forest
+Service.
NEWS.md
table_updateColumn()
to ignore incoming
+locationIDs
that are not found in the
+locationTbl
.table_getDistanceFromTarget()
and edited the description of other distance functions to make clear what each does.table_getDistanceFromTarget()
and edited the
+description of other distance functions to make clear what each
+does.validateMazamaSpatialUtils()
test from table_addCoreMetadata()
as this function just adds empty columns and does not need any spatial data.validateMazamaSpatialUtils()
test from
+table_addCoreMetadata()
as this function just adds empty
+columns and does not need any spatial data.table_addOpenCageInfo()
to handle address components that are missing from the openCage results.table_addOpenCageInfo()
to handle address
+components that are missing from the openCage results.table_findAdjacentLocations()
to only only return unique locations and to ensure they are returned in order of separation distance.jitter = 0
in table_leaflet()
and table_leafletAdd()
.table_findAdjacentLocations()
to only only
+return unique locations and to ensure they are returned in order of
+separation distance.jitter = 0
in
+table_leaflet()
and table_leafletAdd()
.table_filterByDistance()
.location_getOpenCageInfo()
to get OpenCage information for a single location.location_getOpenCageInfo()
to get OpenCage
+information for a single location.location_getCensusBlock()
to add censusYear
argument.location_getCensusBlock()
to add
+censusYear
argument.table_addOpenCageInfo()
with support for reverse geocoding using tidygeocoder.table_addOpenCageInfo()
with support for reverse
+geocoding using tidygeocoder.mazama_initialize()
now only loads the high resolution datasets used in location_initialize()
.mazama_initialize()
now only loads the high resolution
+datasets used in location_initialize()
.
match.arg()
.table_load()
looks for .rda and then .csv versions.table_save()
to avoid deprecated arguments to readr::write_csv()
.match.arg()
.table_load()
looks for .rda and then .csv
+versions.table_save()
to avoid deprecated arguments to
+readr::write_csv()
.table_load()
and table_save()
.table_export()
. Use table_save()
instead.table_load()
and
+table_save()
.table_export()
. Use table_save()
+instead.~APIKey()
functionality. Now importing this from MazamaCoreUtils
0.4.10.table_getLocationID()
and table_getNearestDistance()
by only calculating distance for unique locations. This helps tremendously when longitude
and latitude
come from “tidy” dataframes.~APIKey()
functionality. Now importing this
+from MazamaCoreUtils
0.4.10.table_getLocationID()
and
+table_getNearestDistance()
by only calculating distance for
+unique locations. This helps tremendously when longitude
+and latitude
come from “tidy” dataframes.table_initializeExisting()
.table_initializeExisting()
.table_leaflet()
and table_leafletAdd()
with improved defaults and more flexibility.table_leaflet()
and
+table_leafletAdd()
with improved defaults and more
+flexibility.county
to countyName
. (This change more closely matches spatial metadata found in other systems and fits with the pattern of ~Code
/~Name
pairs in MazamaSpatialUtils as is the case with countryCode/CountryName
and stateCode/stateName
.)county
to countyName
. (This change
+more closely matches spatial metadata found in other systems and fits
+with the pattern of ~Code
/~Name
pairs in
+MazamaSpatialUtils as is the case with
+countryCode/CountryName
and
+stateCode/stateName
.)table_findAdjacentDistances()
when only two locations are adjacent.table_findAdjacentDistances()
when only
+two locations are adjacent.table_updateColumn()
now ignores NA
values in locationID
.table_updateColumn()
now ignores NA
values
+in locationID
.
validateLonLat()
, validateLonsLats()
, createLocationID()
.validateLonLat()
, validateLonsLats()
,
+createLocationID()
.Version 0.2.x focuses on usability improvements after initial work with the package.
+Version 0.2.x focuses on usability improvements after initial work +with the package.
radius
to distanceThreshold
throughout for clarity.table_initializeExisting()
to only perform spatial searches where data are missing in the incoming table. This greatly speeds up performance.table_leafletAdd()
function to make it easier to compare “known locations” tables."table_addCoreMetadata()
function adds columns of NA
values for any missing core metadata but does not perform any spatial calculations.table_findAdjacentLocations()
function returns a tibble of all locations that are too close (i.e. separated by < distanceThreshold
).radius
to
+distanceThreshold
throughout for clarity.table_initializeExisting()
to only perform
+spatial searches where data are missing in the incoming table. This
+greatly speeds up performance.table_leafletAdd()
function to make it easier to
+compare “known locations” tables.”table_addCoreMetadata()
function adds columns of
+NA
values for any missing core metadata but does not
+perform any spatial calculations.table_findAdjacentLocations()
function returns a
+tibble of all locations that are too close (i.e. separated by
+< distanceThreshold
).table_findOverlappingLocations()
renamed to table_findAdjacentDistances()
.measure
argument to table_findAdjacentLocations()
, table_findAdjacentDistances()
, table_getLocationID()
and table_getNearestDistance()
.na.rm
argument to validateLonsLats()
.table_~()
functions.locationTbl
whenever an incoming table includes longitude
and latitude
variables.table_leaflet()
function to display locations and metadata.table_findOverlappingLocations()
renamed to
+table_findAdjacentDistances()
.
+measure
argument to
+table_findAdjacentLocations()
,
+table_findAdjacentDistances()
,
+table_getLocationID()
and
+table_getNearestDistance()
.na.rm
argument to
+validateLonsLats()
.table_~()
+functions.locationTbl
whenever an incoming table includes
+longitude
and latitude
variables.table_leaflet()
function to display locations and
+metadata.location_getSingleAddress_Photon()
to remove revgeo dependency.location_getSingleAddress_Photon()
to remove
+revgeo dependency.geodist::geodist()
is now always called with measure = "geodesic"
to avoid warning messages from geodist()
about inaccuracies with measure = "cheap"
(the geodist()
default).geodist::geodist()
is now always called with
+measure = "geodesic"
to avoid warning messages from
+geodist()
about inaccuracies with
+measure = "cheap"
(the geodist()
+default).
mazama_initialize()
now installs required datasets if they are missing.mazama_initialize()
now installs required datasets if
+they are missing.
table_findOverlappingLocations()
.table_findOverlappingLocations()
.table_initializeExisting()
for fast conversion of an existing table of spatial metadata into a standardized “known location” table.table_findOverlappingLocations()
to help choose an appropriate radius when initializing from an existing metadata table.addressService
argument to table_addLocation()
, table_addSingleLocation() and
location_initialize()` to skip the address step that requires web services.table_initializeExisting()
for fast conversion of
+an existing table of spatial metadata into a standardized “known
+location” table.table_findOverlappingLocations()
to help choose
+an appropriate radius when initializing from an existing metadata
+table.addressService
argument to
+table_addLocation()
,
+table_addSingleLocation() and
location_initialize()` to skip
+the address step that requires web services.setAPIKey()
and getAPIKey()
.setAPIKey()
and
+getAPIKey()
.getLoations()
getLocationID()
and getNearestLocation()
+getLocationID()
and
+getNearestLocation()
For matching locationID
, records the associated
-locationData
is used to replace any existing value in columnName
.
-NA
values in locationID
will be ignored.
Updates records in a location table. Records are identified
+by locationID
and the data found in locationData
is used to
+replace any existing value in the columnName
column.
+locationID
and locationData
must be of the same length.
+Any NA
values in locationID
will be ignored.
If columnName
is not a named column within locationTbl
, a new
+column will be created.
table_updateColumn( @@ -144,7 +152,8 @@Arg
columnName -+ Name to use for the new column.
Name of an existing/new column in
locationTbl
whose data +will be updated/created.locationID @@ -152,7 +161,8 @@Arg
locationData -+ Vector of data to used at matching records.
Vector of data to be inserted at records identified by +
locationID
.verbose diff --git a/docs/reference/table_updateSingleRecord.html b/docs/reference/table_updateSingleRecord.html index e2c95c9..17db282 100644 --- a/docs/reference/table_updateSingleRecord.html +++ b/docs/reference/table_updateSingleRecord.html @@ -76,7 +76,7 @@ diff --git a/docs/reference/validateLocationTbl.html b/docs/reference/validateLocationTbl.html index 7682888..e181637 100644 --- a/docs/reference/validateLocationTbl.html +++ b/docs/reference/validateLocationTbl.html @@ -73,7 +73,7 @@ diff --git a/docs/reference/validateLonLat.html b/docs/reference/validateLonLat.html index 656afa1..53a5bf3 100644 --- a/docs/reference/validateLonLat.html +++ b/docs/reference/validateLonLat.html @@ -77,7 +77,7 @@ diff --git a/docs/reference/validateLonsLats.html b/docs/reference/validateLonsLats.html index fe9073a..326ff58 100644 --- a/docs/reference/validateLonsLats.html +++ b/docs/reference/validateLonsLats.html @@ -77,7 +77,7 @@ diff --git a/docs/reference/validateMazamaSpatialUtils.html b/docs/reference/validateMazamaSpatialUtils.html index 14d0d37..823a93b 100644 --- a/docs/reference/validateMazamaSpatialUtils.html +++ b/docs/reference/validateMazamaSpatialUtils.html @@ -74,7 +74,7 @@ diff --git a/docs/reference/wa_airfire_meta.html b/docs/reference/wa_airfire_meta.html index 83d4df7..87a9c06 100644 --- a/docs/reference/wa_airfire_meta.html +++ b/docs/reference/wa_airfire_meta.html @@ -85,7 +85,7 @@ diff --git a/docs/reference/wa_monitors_500.html b/docs/reference/wa_monitors_500.html index 85c2c13..80e0029 100644 --- a/docs/reference/wa_monitors_500.html +++ b/docs/reference/wa_monitors_500.html @@ -95,7 +95,7 @@ diff --git a/man/table_updateColumn.Rd b/man/table_updateColumn.Rd index d589b3b..35efa20 100644 --- a/man/table_updateColumn.Rd +++ b/man/table_updateColumn.Rd @@ -15,11 +15,13 @@ table_updateColumn( \arguments{ \item{locationTbl}{Tibble of known locations.} -\item{columnName}{Name to use for the new column.} +\item{columnName}{Name of an existing/new column in \code{locationTbl} whose data +will be updated/created.} \item{locationID}{Vector of \code{locationID} strings.} -\item{locationData}{Vector of data to used at matching records.} +\item{locationData}{Vector of data to be inserted at records identified by +\code{locationID}.} \item{verbose}{Logical controlling the generation of progress messages.} } @@ -27,9 +29,14 @@ table_updateColumn( Updated tibble of known locations. } \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. +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. } \examples{ library(MazamaLocationUtils) diff --git a/tests/testthat/test-table_updateColumn.R b/tests/testthat/test-table_updateColumn.R index 6255a2b..d102dd8 100644 --- a/tests/testthat/test-table_updateColumn.R +++ b/tests/testthat/test-table_updateColumn.R @@ -21,6 +21,7 @@ test_that("table_updateColumn() works with data", { locationID <- table_getLocationID(locationTbl, wa_sub$longitude, wa_sub$latitude, distanceThreshold = 1000) locationData <- wa_sub$siteName + # Create a new column testTbl <- table_updateColumn(locationTbl, "siteName", locationID, locationData) testTbl_indices <- table_getRecordIndex(testTbl, locationID) @@ -34,3 +35,28 @@ test_that("table_updateColumn() works with data", { }) +test_that("table_updateColumn() skips unknown locations", { + + locationTbl <- get(data("wa_monitors_500")) + wa <- get(data("wa_airfire_meta")) + + # Record indices into for wa + wa_indices <- seq(5,65,5) + wa_sub <- wa[wa_indices,] + + # NOTE: Include locationIDs not found in locationTbl + locationID <- c("locationID_NOT_FOUND", table_getLocationID(locationTbl, wa_sub$longitude, wa_sub$latitude, distanceThreshold = 1000)) + locationData <- c("locationData_NOT_FOUND", wa_sub$siteName) + + # update an Existing column + testTbl <- table_updateColumn(locationTbl, "locationName", locationID, locationData) + testTbl_indices <- + table_getRecordIndex(testTbl, locationID) %>% + na.omit() %>% as.numeric() + + expect_true({ + all( testTbl$locationName[testTbl_indices] %in% wa$siteName ) + }) + +}) +