diff --git a/DESCRIPTION b/DESCRIPTION index 101d0fc5..4df9e8d4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,7 +34,10 @@ Authors@R: c( comment=c(ORCID = "0000-0001-5396-1583")), person("Michael", "Mahoney", role="ctb", email = "mjmahoney@usgs.gov", - comment=c(ORCID = "0000-0003-2402-304X")) + comment=c(ORCID = "0000-0003-2402-304X")), + person("Matthew", "Conlon", role="ctb", + email = "mconlon@usgs.gov", + comment=c(ORCID = "0000-0001-8266-9610")) ) Description: Collection of functions to help retrieve U.S. Geological Survey and U.S. Environmental Protection Agency water quality and diff --git a/NAMESPACE b/NAMESPACE index ea42a034..58e18e70 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,9 +27,6 @@ export(pCodeToName) export(parameterCdFile) export(parse_WQP) export(pcode_to_name) -export(readNGWMNdata) -export(readNGWMNlevels) -export(readNGWMNsites) export(readNWISdata) export(readNWISdv) export(readNWISpCode) @@ -58,6 +55,7 @@ export(read_waterdata_field_measurements) export(read_waterdata_field_meta) export(read_waterdata_latest_continuous) export(read_waterdata_latest_daily) +export(read_waterdata_latest_field_measurements) export(read_waterdata_metadata) export(read_waterdata_monitoring_location) export(read_waterdata_parameter_codes) diff --git a/R/AAA.R b/R/AAA.R index ad96e464..1cd88cad 100644 --- a/R/AAA.R +++ b/R/AAA.R @@ -3,7 +3,9 @@ pkg.env <- new.env() .onLoad <- function(libname, pkgname) { suppressMessages(setAccess("public")) pkg.env$local_sf <- requireNamespace("sf", quietly = TRUE) - options("dataRetrieval.nldi_base" = "https://api.water.usgs.gov/nldi/linked-data/") + options( + "dataRetrieval.nldi_base" = "https://api.water.usgs.gov/nldi/linked-data/" + ) options("dataRetrieval.api_version" = "v0") options("dataRetrieval.api_version_stat" = "v0") options("dataRetrieval.attach_request" = TRUE) @@ -21,6 +23,7 @@ pkg.env <- new.env() "latest-continuous", "field-measurements", "latest-daily", + "latest-field-measurements", "continuous", "field-measurements-metadata", "combined-metadata", diff --git a/R/readNGWMNdata.R b/R/readNGWMNdata.R deleted file mode 100644 index f9c9a621..00000000 --- a/R/readNGWMNdata.R +++ /dev/null @@ -1,226 +0,0 @@ -#' Import data from the National Groundwater Monitoring Network. -#' -#' Only water level data and site locations and names are currently available through the web service. -#' @param service char Service for the request - "observation" and "featureOfInterest" are implemented. -#' @param \dots Other parameters to supply, namely `siteNumbers` or `bbox` -#' @param asDateTime logical if `TRUE`, will convert times to POSIXct format. Currently defaults to -#' `FALSE` since time zone information is not included. -#' @param tz character to set timezone attribute of dateTime. Default is "UTC", and converts the -#' date times to UTC, properly accounting for daylight savings times based on the data's provided time zone offset. -#' Possible values to provide are "America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles", -#' "America/Anchorage", as well as the following which do not use daylight savings time: "America/Honolulu", -#' "America/Jamaica", "America/Managua", "America/Phoenix", and "America/Metlakatla". See also `OlsonNames()` -#' for more information on time zones. -#' @export -readNGWMNdata <- function(service, ..., asDateTime = TRUE, tz = "UTC") { - .Deprecated( - new = "read_ngwmn_water_level", - package = "dataRetrieval", - msg = "Updated NGWMN APIs will use read_ngwmn set of functions." - ) - - dots <- convertLists(...) - - match.arg(service, c("observation", "featureOfInterest")) - - if (service == "observation") { - # these attributes are pulled out and saved when doing binds to be reattached - attrs <- c( - "url", - "gml:identifier", - "generationDate", - "responsibleParty", - "contact" - ) - featureID <- stats::na.omit(gsub(":", ".", dots[["siteNumbers"]])) - - obs_list <- vector("list", length(featureID)) - attr_list <- vector("list", length(featureID)) - for (idx in seq_along(featureID)) { - obsFID <- retrieveObservation( - featureID = featureID[idx], - asDateTime, - attrs, - tz = tz - ) - attr_list[[idx]] <- saveAttrs(attrs, obsFID) - obs_list[[idx]] <- removeAttrs(attrs, obsFID) - } - allObs <- Reduce(r_bind_dr, obs_list, init = data.frame()) - allAttrs <- Reduce(r_bind_dr, attr_list, init = data.frame()) - - allSites <- tryCatch( - { - retrieveFeatureOfInterest(featureID = featureID) - }, - error = function(cond) { - return(NULL) - } - ) - - if (!is.null(allSites)) { - attr(allObs, "siteInfo") <- allSites - } - - attr(allObs, "other") <- allAttrs - returnData <- allObs - } else if (service == "featureOfInterest") { - if ("siteNumbers" %in% names(dots)) { - featureID <- stats::na.omit(gsub(":", ".", dots[["siteNumbers"]])) - allSites <- tryCatch({ - retrieveFeatureOfInterest(featureID = featureID) - }) - } - - if ("bbox" %in% names(dots)) { - allSites <- tryCatch({ - retrieveFeatureOfInterest(bbox = dots[["bbox"]]) - }) - } - returnData <- allSites - } - - return(returnData) -} - -#' Retrieve groundwater levels from the National Ground Water Monitoring Network. -#' -#' @param siteNumbers character Vector of feature IDs formatted with agency code and site number -#' separated by a period or semicolon, e.g. `USGS.404159100494601`. -#' @param asDateTime logical Should dates and times be converted to date/time objects, -#' or returned as character? Defaults to `TRUE`. Must be set to `FALSE` if a site -#' contains non-standard dates. -#' @param tz character to set timezone attribute of dateTime. Default is "UTC", and converts the -#' date times to UTC, properly accounting for daylight savings times based on the data's provided time zone offset. -#' Possible values to provide are "America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles", -#' "America/Anchorage", as well as the following which do not use daylight savings time: "America/Honolulu", -#' "America/Jamaica", "America/Managua", "America/Phoenix", and "America/Metlakatla". See also `OlsonNames()` -#' for more information on time zones. -#' @export -readNGWMNlevels <- function(siteNumbers, asDateTime = TRUE, tz = "UTC") { - data <- readNGWMNdata( - siteNumbers = siteNumbers, - service = "observation", - asDateTime = asDateTime, - tz = tz - ) - return(data) -} - -#' Retrieve site data from the National Ground Water Monitoring Network. -#' -#' @param siteNumbers character Vector of feature IDs formatted with agency code and site number -#' separated by a period or semicolon, e.g. `USGS.404159100494601`. -#' -#' @export -#' @return A data frame the following columns: -#' #' \tabular{lll}{ -#' Name \tab Type \tab Description \cr -#' site \tab char \tab Site FID \cr -#' description \tab char \tab Site description \cr -#' dec_lat_va, dec_lon_va \tab numeric \tab Site latitude and longitude \cr -#' } - -readNGWMNsites <- function(siteNumbers) { - sites <- readNGWMNdata( - siteNumbers = siteNumbers, - service = "featureOfInterest" - ) - return(sites) -} - -retrieveObservation <- function(featureID, asDateTime, attrs, tz) { - baseURL <- httr2::request(pkg.env[["NGWMN"]]) - baseURL <- httr2::req_url_query( - baseURL, - request = "GetObservation", - service = "SOS", - version = "2.0.0", - observedProperty = "urn:ogc:def:property:OGC:GroundWaterLevel", - responseFormat = "text/xml", - featureOfInterest = paste("VW_GWDP_GEOSERVER", featureID, sep = ".") - ) - - returnData <- importNGWMN(baseURL, asDateTime = asDateTime, tz = tz) - if (nrow(returnData) == 0) { - # need to add NA attributes, so they aren't messed up when stored as DFs - attr(returnData, "gml:identifier") <- NA - attr(returnData, "generationDate") <- NA - } - - # mutate removes the attributes, need to save and append - attribs <- saveAttrs(attrs, returnData) - if (nrow(returnData) > 0) { - # tack on site number - siteNum <- rep(sub(".*\\.", "", featureID), nrow(returnData)) - returnData$site <- siteNum - numCol <- ncol(returnData) - returnData <- returnData[, c(numCol, 1:(numCol - 1))] # move siteNum to the left - } - attributes(returnData) <- c(attributes(returnData), as.list(attribs)) - - return(returnData) -} - -# retrieve feature of interest -# could allow pass through srsName - needs to be worked in higher-up in dots -retrieveFeatureOfInterest <- function( - ..., - asDateTime, - srsName = "urn:ogc:def:crs:EPSG::4269" -) { - values <- convertLists(...) - - baseURL <- httr2::request(pkg.env[["NGWMN"]]) - baseURL <- httr2::req_url_query( - baseURL, - request = "GetFeatureOfInterest", - service = "SOS", - version = "2.0.0", - responseFormat = "text/xml" - ) - - if ("featureID" %in% names(values)) { - features <- paste("VW_GWDP_GEOSERVER", values[["featureID"]], sep = ".") - - baseURL <- httr2::req_url_query( - baseURL, - featureOfInterest = features, - .multi = "comma" - ) - } else if ("bbox" %in% names(values)) { - baseURL <- httr2::req_url_query( - baseURL, - bbox = paste(values[["bbox"]], collapse = ","), - srsName = srsName - ) - } else { - stop("Geographical filter not specified. Please use siteNumbers or bbox") - } - - siteDF <- importNGWMN(baseURL, asDateTime, tz = "") - attr(siteDF, "url") <- baseURL$url - attr(siteDF, "queryTime") <- Sys.time() - return(siteDF) -} - - -# save specified attributes from a data frame -saveAttrs <- function(attrs, df) { - attribs <- sapply(attrs, function(x) attr(df, x)) - if (is.vector(attribs)) { - toReturn <- as.data.frame(t(attribs), stringsAsFactors = FALSE) - } else { - # don't need to transpose - toReturn <- as.data.frame(attribs, stringsAsFactors = FALSE) - } - return(toReturn) -} - -# strip specified attributes from a data frame -removeAttrs <- function(attrs, df) { - for (a in attrs) { - attr(df, a) <- NULL - } - return(df) -} diff --git a/R/read_waterdata_continuous.R b/R/read_waterdata_continuous.R index d9291e56..eff8cc87 100644 --- a/R/read_waterdata_continuous.R +++ b/R/read_waterdata_continuous.R @@ -8,7 +8,6 @@ #' for new direct download functions that are expected to be available sometime #' in 2026. #' -#' Geometry output is not supported in the continuous data API endpoint. #' #' @export #' @param monitoring_location_id `r get_ogc_params("continuous")$monitoring_location_id` @@ -35,6 +34,7 @@ #' @param \dots Not used. Included to help differentiate official Water Data API arguments #' from more seldom used, optional dataRetrieval-specific arguments. #' @inheritParams check_arguments_non_api +#' @inheritParams check_arguments_api #' #' @details #' You can also use a vector of length 2 for any time queries (such as time @@ -120,6 +120,8 @@ read_waterdata_continuous <- function( value = NA, last_modified = NA_character_, time = NA_character_, + skipGeometry = TRUE, + bbox = NA, ..., convertType = getOption("dataRetrieval.convertType"), limit = getOption("dataRetrieval.limit"), @@ -132,7 +134,6 @@ read_waterdata_continuous <- function( rlang::check_dots_empty() args <- mget(names(formals())) - args[["skipGeometry"]] <- TRUE return_list <- get_ogc_data(args, output_id, service) diff --git a/R/read_waterdata_latest_field.R b/R/read_waterdata_latest_field.R new file mode 100644 index 00000000..f7a1dcf2 --- /dev/null +++ b/R/read_waterdata_latest_field.R @@ -0,0 +1,81 @@ +#' Get latest USGS field measurement data +#' +#' @description `r get_description("latest-field-measurements")` +#' +#' @export +#' @param monitoring_location_id `r get_ogc_params("latest-field-measurements")$monitoring_location_id` +#' Multiple monitoring_location_ids can be requested as a character vector. +#' @param parameter_code `r get_ogc_params("latest-field-measurements")$parameter_code` +#' Multiple parameter_codes can be requested as a character vector. +#' @param statistic_id `r get_ogc_params("latest-field-measurements")$statistic_id` +#' Multiple statistic_ids can be requested as a character vector. +#' @param time `r get_ogc_params("latest-field-measurements")$time` +#' +#' See also Details below for more information. +#' @param value `r get_ogc_params("latest-field-measurements")$value` +#' @param unit_of_measure `r get_ogc_params("latest-field-measurements")$unit_of_measure` +#' @param approval_status `r get_ogc_params("latest-field-measurements")$approval_status` +#' @param last_modified `r get_ogc_params("latest-field-measurements")$last_modified` +#' +#' See also Details below for more information. +#' @param time_series_id `r get_ogc_params("latest-field-measurements")$time_series_id` +#' Multiple time_series_ids can be requested as a character vector. +#' @param qualifier `r get_ogc_params("latest-field-measurements")$qualifier` +#' @param properties A vector of requested columns to be returned from the query. +#' Available options are: +#' `r dataRetrieval:::get_properties_for_docs("latest-field-measurements", "latest_field_id")`. +#' The default (`NA`) will return all columns of the data. +#' +#' @inheritParams check_arguments_api +#' @inheritParams check_arguments_non_api +#' @inherit read_waterdata_continuous details +#' +#' @examplesIf is_dataRetrieval_user() +#' +#' \donttest{ +#' site <- "USGS-01435000" +#' +#' field_data_sf <- read_waterdata_latest_field_measurements(monitoring_location_id = site) +#' +#' dv_data_trim <- read_waterdata_latest_field_measurements(monitoring_location_id = site, +#' properties = c("monitoring_location_id", +#' "value", +#' "time")) +#' +#' field_data <- read_waterdata_latest_field_measurements(monitoring_location_id = site, +#' skipGeometry = TRUE) +#' +#' multi_site <- read_waterdata_latest_field_measurements(monitoring_location_id = c("USGS-01435000", +#' "USGS-14202650")) +#' +#' } +read_waterdata_latest_field_measurements <- function( + monitoring_location_id = NA_character_, + parameter_code = NA_character_, + statistic_id = NA_character_, + properties = NA_character_, + time_series_id = NA_character_, + approval_status = NA_character_, + unit_of_measure = NA_character_, + qualifier = NA_character_, + value = NA, + last_modified = NA_character_, + skipGeometry = NA, + time = NA_character_, + bbox = NA, + ..., + convertType = getOption("dataRetrieval.convertType"), + no_paging = getOption("dataRetrieval.no_paging"), + limit = getOption("dataRetrieval.limit"), + chunk_size = getOption("dataRetrieval.site_chunk_size_meta"), + attach_request = getOption("dataRetrieval.attach_request") +) { + service <- "latest-field-measurements" + output_id <- "latest_field_id" + rlang::check_dots_empty() + + args <- mget(names(formals())) + return_list <- get_ogc_data(args, output_id, service) + + return(return_list) +} diff --git a/R/read_waterdata_ratings.R b/R/read_waterdata_ratings.R index 3663592a..cfe02427 100644 --- a/R/read_waterdata_ratings.R +++ b/R/read_waterdata_ratings.R @@ -38,7 +38,13 @@ #' @export #' @inherit read_waterdata_continuous details #' -#' @return List of data frames which contain the requested rating curves. +#' @return List of named lists, one per requested rating file. Each element +#' contains: +#' \describe{ +#' \item{ratings}{Data frame of the rating curve.} +#' \item{metadata}{Data frame of header/value pairs parsed from the comment +#' attribute of the ratings file.} +#' } #' #' @examplesIf is_dataRetrieval_user() #' @@ -49,15 +55,15 @@ #' monitoring_location_id = monitoring_location_id, #' file_type = "exsa") #' -#' head(ratings_exsa[["USGS-01104475.exsa.rdb"]]) -#' comment(ratings_exsa[["USGS-01104475.exsa.rdb"]])[1:15] +#' head(ratings_exsa[["USGS-01104475.exsa.rdb"]]$ratings) +#' ratings_exsa[["USGS-01104475.exsa.rdb"]]$metadata #' #' ratings_corr <- read_waterdata_ratings( #' monitoring_location_id = monitoring_location_id, #' file_type = "corr") #' -#' head(ratings_corr[["USGS-01104460.corr.rdb"]]) -#' comment(ratings_corr[["USGS-01104460.corr.rdb"]])[1:15] +#' head(ratings_corr[["USGS-01104460.corr.rdb"]]$ratings) +#' ratings_corr[["USGS-01104460.corr.rdb"]]$metadata #' #' rating_2 <- read_waterdata_ratings( #' monitoring_location_id = monitoring_location_id, @@ -147,6 +153,8 @@ read_waterdata_ratings <- function( httr2::req_url_query(limit = limit) |> basic_request() + message("Requesting:\n", request$url) + resp <- httr2::req_perform(request) log_rate_limit(resp) @@ -168,6 +176,7 @@ read_waterdata_ratings <- function( } } +# Download and convert a rating curve feature to a tidy list download_convert <- function(feature, file_path, file_type) { links <- feature$links id <- feature$id @@ -181,8 +190,135 @@ download_convert <- function(feature, file_path, file_type) { message("Requesting: \n", url) resp <- httr2::req_perform(req, path = full_file_path) rating <- importRDB1(full_file_path) - return(rating) + return(list( + ratings = rating, + metadata = parse_ratings_metadata(rating) + )) } return(NULL) } + +# Parse rating comment metadata into a data frame +parse_ratings_metadata <- function(ratings_df) { + raw_comments <- comment(ratings_df) + + if (is.null(raw_comments)) { + return(data.frame( + header = character(), + value = character() + )) + } + + com <- data.frame( + line = raw_comments + ) + + # remove whitespace + com$line <- sub("^#\\s*//?", "", com$line) + com$line <- sub("^//", "", com$line) + com$line <- gsub("\\s+", " ", trimws(com$line)) + + # concatenate warning info + warn_rows <- grepl("^WARNING", com$line) + warn_text <- sub("^WARNING\\s*", "", com$line[warn_rows]) + warn_text <- gsub("\\s+", " ", trimws(warn_text)) + warn_text <- warn_text[warn_text != ""] + + warning_block <- if (length(warn_text) > 0) { + paste(warn_text, collapse = " ") + } else { + "" + } + + non_warn <- com[!warn_rows, , drop = FALSE] + + # group the key-value pairs in the data + kv_pat <- '[A-Za-z0-9_]+\\s*=\\s*"[^"]*"|[A-Za-z0-9_]+\\s*=\\s*[^\\s]+' + kv_match <- regmatches( + non_warn$line, + gregexpr(kv_pat, non_warn$line, perl = TRUE) + ) + has_kv <- sapply(kv_match, length) > 0 + kv_flat <- unlist(kv_match, use.names = FALSE) + + pairs_df <- data.frame( + header = sub("^([A-Za-z0-9_]+).*", "\\1", kv_flat, perl = TRUE), + value = gsub( + '^"|"$', + "", + gsub( + "\\s+", + " ", + trimws( + sub("^[A-Za-z0-9_]+\\s*=\\s*", "", kv_flat, perl = TRUE) + ) + ) + ) + ) + + # handle data with colons + colon_pat <- "^[A-Z][A-Z _-]+:" + colon_rows <- grepl(colon_pat, non_warn$line) + colon_lines <- non_warn$line[colon_rows] + + date_df <- data.frame( + header = gsub( + "\\s+", + " ", + trimws( + sub("^([A-Z][A-Z _-]+):.*$", "\\1", colon_lines, perl = TRUE) + ) + ), + value = gsub( + "\\s+", + " ", + trimws( + sub("^[A-Z][A-Z _-]+:\\s*", "", colon_lines, perl = TRUE) + ) + ) + ) + + # parse any lines that don't fit other patterns + other_lines <- non_warn$line[!has_kv & !colon_rows] + + other_df <- data.frame( + header = gsub( + "\\s+", + " ", + trimws( + sub("^([A-Z][A-Z _-]+).*$", "\\1", other_lines, perl = TRUE) + ) + ), + value = gsub( + "\\s+", + " ", + trimws( + sub("^[A-Z][A-Z _-]+\\s*", "", other_lines, perl = TRUE) + ) + ) + ) + + # combine into one dataframe to be added to list object + final <- rbind( + data.frame( + header = "WARNING", + value = warning_block + ), + pairs_df, + date_df, + other_df + ) + + final$value <- gsub("[\\x00-\\x1F\\x7F]+", " ", final$value, perl = TRUE) + final$value <- gsub("\\s+", " ", trimws(final$value)) + final$header <- gsub("\\s+", " ", trimws(final$header)) + + final <- final[!(final$header == "" & final$value == ""), , drop = FALSE] + final <- unique(final) + rownames(final) <- final$header + # final_t <- data.frame(t(final)) + rownames(final) <- NULL + + final +} diff --git a/_pkgdown.yml b/_pkgdown.yml index 38223dae..dacf3d73 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -79,6 +79,7 @@ reference: - read_waterdata_monitoring_location - read_waterdata_latest_continuous - read_waterdata_latest_daily + - read_waterdata_latest_field - read_waterdata_field_measurements - read_waterdata_parameter_codes - read_waterdata_metadata diff --git a/man/readNGWMNdata.Rd b/man/readNGWMNdata.Rd deleted file mode 100644 index b56d0dbe..00000000 --- a/man/readNGWMNdata.Rd +++ /dev/null @@ -1,26 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readNGWMNdata.R -\name{readNGWMNdata} -\alias{readNGWMNdata} -\title{Import data from the National Groundwater Monitoring Network.} -\usage{ -readNGWMNdata(service, ..., asDateTime = TRUE, tz = "UTC") -} -\arguments{ -\item{service}{char Service for the request - "observation" and "featureOfInterest" are implemented.} - -\item{\dots}{Other parameters to supply, namely \code{siteNumbers} or \code{bbox}} - -\item{asDateTime}{logical if \code{TRUE}, will convert times to POSIXct format. Currently defaults to -\code{FALSE} since time zone information is not included.} - -\item{tz}{character to set timezone attribute of dateTime. Default is "UTC", and converts the -date times to UTC, properly accounting for daylight savings times based on the data's provided time zone offset. -Possible values to provide are "America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles", -"America/Anchorage", as well as the following which do not use daylight savings time: "America/Honolulu", -"America/Jamaica", "America/Managua", "America/Phoenix", and "America/Metlakatla". See also \code{OlsonNames()} -for more information on time zones.} -} -\description{ -Only water level data and site locations and names are currently available through the web service. -} diff --git a/man/readNGWMNlevels.Rd b/man/readNGWMNlevels.Rd deleted file mode 100644 index 64637e52..00000000 --- a/man/readNGWMNlevels.Rd +++ /dev/null @@ -1,26 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readNGWMNdata.R -\name{readNGWMNlevels} -\alias{readNGWMNlevels} -\title{Retrieve groundwater levels from the National Ground Water Monitoring Network.} -\usage{ -readNGWMNlevels(siteNumbers, asDateTime = TRUE, tz = "UTC") -} -\arguments{ -\item{siteNumbers}{character Vector of feature IDs formatted with agency code and site number -separated by a period or semicolon, e.g. \code{USGS.404159100494601}.} - -\item{asDateTime}{logical Should dates and times be converted to date/time objects, -or returned as character? Defaults to \code{TRUE}. Must be set to \code{FALSE} if a site -contains non-standard dates.} - -\item{tz}{character to set timezone attribute of dateTime. Default is "UTC", and converts the -date times to UTC, properly accounting for daylight savings times based on the data's provided time zone offset. -Possible values to provide are "America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles", -"America/Anchorage", as well as the following which do not use daylight savings time: "America/Honolulu", -"America/Jamaica", "America/Managua", "America/Phoenix", and "America/Metlakatla". See also \code{OlsonNames()} -for more information on time zones.} -} -\description{ -Retrieve groundwater levels from the National Ground Water Monitoring Network. -} diff --git a/man/readNGWMNsites.Rd b/man/readNGWMNsites.Rd deleted file mode 100644 index 4b5c92be..00000000 --- a/man/readNGWMNsites.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readNGWMNdata.R -\name{readNGWMNsites} -\alias{readNGWMNsites} -\title{Retrieve site data from the National Ground Water Monitoring Network.} -\usage{ -readNGWMNsites(siteNumbers) -} -\arguments{ -\item{siteNumbers}{character Vector of feature IDs formatted with agency code and site number -separated by a period or semicolon, e.g. \code{USGS.404159100494601}.} -} -\value{ -A data frame the following columns: -#' \tabular{lll}{ -Name \tab Type \tab Description \cr -site \tab char \tab Site FID \cr -description \tab char \tab Site description \cr -dec_lat_va, dec_lon_va \tab numeric \tab Site latitude and longitude \cr -} -} -\description{ -Retrieve site data from the National Ground Water Monitoring Network. -} diff --git a/man/read_waterdata_combined_meta.Rd b/man/read_waterdata_combined_meta.Rd index 4e7a3519..f5147793 100644 --- a/man/read_waterdata_combined_meta.Rd +++ b/man/read_waterdata_combined_meta.Rd @@ -185,7 +185,7 @@ See also Details below for more information.} \item{site_type}{A description of the hydrologic setting of the monitoring location. A list of codes is available at \url{https://api.waterdata.usgs.gov/ogcapi/v0/collections/site-types/items}.} -\item{hydrologic_unit_code}{The United States is divided and sub-divided into successively smaller hydrologic units which are classified into four levels: regions, sub-regions, accounting units, and cataloging units. The hydrologic units are arranged within each other, from the smallest (cataloging units) to the largest (regions). Each hydrologic unit is identified by a unique hydrologic unit code (HUC) consisting of two to eight digits based on the four levels of classification in the hydrologic unit system.} +\item{hydrologic_unit_code}{The hydrologic unit code (HUC) for the monitoring location. Supports prefix matching — querying with a shorter HUC (e.g. "04") matches all locations within that hydrologic region.} \item{basin_code}{The Basin Code or "drainage basin code" is a two-digit code that further subdivides the 8-digit hydrologic-unit code. The drainage basin code is defined by the USGS State Office where the monitoring location is located.} @@ -237,7 +237,7 @@ See also Details below for more information.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, monitoring_location_id, agency_code, agency_name, monitoring_location_number, monitoring_location_name, district_code, country_code, country_name, state_code, state_name, county_code, county_name, minor_civil_division_code, site_type_code, site_type, hydrologic_unit_code, basin_code, altitude, altitude_accuracy, altitude_method_code, altitude_method_name, vertical_datum, vertical_datum_name, horizontal_positional_accuracy_code, horizontal_positional_accuracy, horizontal_position_method_code, horizontal_position_method_name, original_horizontal_datum, original_horizontal_datum_name, drainage_area, contributing_drainage_area, time_zone_abbreviation, uses_daylight_savings, construction_date, aquifer_code, national_aquifer_code, aquifer_type_code, well_constructed_depth, hole_constructed_depth, depth_source_code, field_measurement_id, unit_of_measure, parameter_name, parameter_code, statistic_id, last_modified, begin, end, data_type, computation_identifier, thresholds, sublocation_identifier, primary, web_description, parameter_description, parent_time_series_id. +geometry, monitoring_location_id, agency_code, agency_name, monitoring_location_number, monitoring_location_name, district_code, country_code, country_name, state_code, state_name, county_code, county_name, minor_civil_division_code, site_type_code, site_type, hydrologic_unit_code, basin_code, altitude, altitude_accuracy, altitude_method_code, altitude_method_name, vertical_datum, vertical_datum_name, horizontal_positional_accuracy_code, horizontal_positional_accuracy, horizontal_position_method_code, horizontal_position_method_name, original_horizontal_datum, original_horizontal_datum_name, drainage_area, contributing_drainage_area, time_zone_abbreviation, uses_daylight_savings, construction_date, aquifer_code, national_aquifer_code, aquifer_type_code, well_constructed_depth, hole_constructed_depth, depth_source_code, field_measurement_id, unit_of_measure, parameter_name, parameter_code, statistic_id, last_modified, begin, end, data_type, computation_identifier, thresholds, sublocation_identifier, primary, web_description, parameter_description, parent_time_series_id, data_gap_interval, reading_type. The default (\code{NA}) will return all columns of the data.} \item{skipGeometry}{This parameter can be used to skip response geometries for diff --git a/man/read_waterdata_continuous.Rd b/man/read_waterdata_continuous.Rd index e722a5ed..cb48d15b 100644 --- a/man/read_waterdata_continuous.Rd +++ b/man/read_waterdata_continuous.Rd @@ -15,6 +15,8 @@ read_waterdata_continuous( value = NA, last_modified = NA_character_, time = NA_character_, + skipGeometry = TRUE, + bbox = NA, ..., convertType = getOption("dataRetrieval.convertType"), limit = getOption("dataRetrieval.limit"), @@ -76,6 +78,18 @@ Only features that have a \code{time} that intersects the value of datetime are See also Details below for more information.} +\item{skipGeometry}{This parameter can be used to skip response geometries for +each feature. The returning object will be a data frame with no spatial +information. The default \code{NA} will not specify the argument in the request.} + +\item{bbox}{Only features that have a geometry that intersects the bounding +box are selected.The bounding box is provided as four or six numbers, depending +on whether the coordinate reference system includes a vertical axis (height or +depth). Coordinates are assumed to be in crs 4326. The expected format is a numeric +vector structured: c(xmin,ymin,xmax,ymax). +Another way to think of it is c(Western-most longitude, +Southern-most latitude, Eastern-most longitude, Northern-most longitude).} + \item{\dots}{Not used. Included to help differentiate official Water Data API arguments from more seldom used, optional dataRetrieval-specific arguments.} @@ -114,8 +128,6 @@ a single request. If no "time" is specified, the service will return the last single year of data. If this is a bottleneck, please check back for new direct download functions that are expected to be available sometime in 2026. - -Geometry output is not supported in the continuous data API endpoint. } \details{ You can also use a vector of length 2 for any time queries (such as time diff --git a/man/read_waterdata_field_meta.Rd b/man/read_waterdata_field_meta.Rd index 1ecfe588..30bec39a 100644 --- a/man/read_waterdata_field_meta.Rd +++ b/man/read_waterdata_field_meta.Rd @@ -83,7 +83,7 @@ See also Details below for more information.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, field_measurement_id, monitoring_location_id, parameter_code, parameter_name, parameter_description, begin, end, last_modified. +geometry, field_measurement_id, reading_type, monitoring_location_id, parameter_code, parameter_name, parameter_description, begin, end, last_modified. The default (\code{NA}) will return all columns of the data.} \item{skipGeometry}{This parameter can be used to skip response geometries for diff --git a/man/read_waterdata_latest_continuous.Rd b/man/read_waterdata_latest_continuous.Rd index e980a60e..5af72c3f 100644 --- a/man/read_waterdata_latest_continuous.Rd +++ b/man/read_waterdata_latest_continuous.Rd @@ -36,7 +36,7 @@ Multiple parameter_codes can be requested as a character vector.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, latest_continuous_id, time_series_id, monitoring_location_id, parameter_code, statistic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified. +geometry, time_series_id, monitoring_location_id, parameter_code, statistic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified. The default (\code{NA}) will return all columns of the data.} \item{time_series_id}{A unique identifier representing a single time series. This corresponds to the \code{id} field in the \code{time-series-metadata} endpoint. diff --git a/man/read_waterdata_latest_daily.Rd b/man/read_waterdata_latest_daily.Rd index 6eb5a386..3989eb39 100644 --- a/man/read_waterdata_latest_daily.Rd +++ b/man/read_waterdata_latest_daily.Rd @@ -41,7 +41,7 @@ Multiple statistic_ids can be requested as a character vector.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, latest_daily_id, time_series_id, monitoring_location_id, parameter_code, statistic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified. +geometry, time_series_id, monitoring_location_id, parameter_code, statistic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified. The default (\code{NA}) will return all columns of the data.} \item{time_series_id}{A unique identifier representing a single time series. This corresponds to the \code{id} field in the \code{time-series-metadata} endpoint. diff --git a/man/read_waterdata_latest_field_measurements.Rd b/man/read_waterdata_latest_field_measurements.Rd new file mode 100644 index 00000000..3303acfe --- /dev/null +++ b/man/read_waterdata_latest_field_measurements.Rd @@ -0,0 +1,164 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/read_waterdata_latest_field.R +\name{read_waterdata_latest_field_measurements} +\alias{read_waterdata_latest_field_measurements} +\title{Get latest USGS field measurement data} +\usage{ +read_waterdata_latest_field_measurements( + monitoring_location_id = NA_character_, + parameter_code = NA_character_, + statistic_id = NA_character_, + properties = NA_character_, + time_series_id = NA_character_, + approval_status = NA_character_, + unit_of_measure = NA_character_, + qualifier = NA_character_, + value = NA, + last_modified = NA_character_, + skipGeometry = NA, + time = NA_character_, + bbox = NA, + ..., + convertType = getOption("dataRetrieval.convertType"), + no_paging = getOption("dataRetrieval.no_paging"), + limit = getOption("dataRetrieval.limit"), + chunk_size = getOption("dataRetrieval.site_chunk_size_meta"), + attach_request = getOption("dataRetrieval.attach_request") +) +} +\arguments{ +\item{monitoring_location_id}{A unique identifier representing a single monitoring location. This corresponds to the \code{id} field in the \code{monitoring-locations} endpoint. Monitoring location IDs are created by combining the agency code of the agency responsible for the monitoring location (e.g. USGS) with the ID number of the monitoring location (e.g. 02238500), separated by a hyphen (e.g. USGS-02238500). + +Multiple monitoring_location_ids can be requested as a character vector.} + +\item{parameter_code}{Parameter codes are 5-digit codes used to identify the constituent measured and the units of measure. A complete list of parameter codes and associated groupings can be found at \url{https://api.waterdata.usgs.gov/ogcapi/v0/collections/parameter-codes/items}. + +Multiple parameter_codes can be requested as a character vector.} + +\item{statistic_id}{Multiple statistic_ids can be requested as a character vector.} + +\item{properties}{A vector of requested columns to be returned from the query. +Available options are: +geometry, field_measurements_series_id, field_visit_id, parameter_code, monitoring_location_id, observing_procedure_code, observing_procedure, value, unit_of_measure, time, qualifier, vertical_datum, approval_status, measuring_agency, last_modified, control_condition, measurement_rated, year, month, day, time_of_day. +The default (\code{NA}) will return all columns of the data.} + +\item{time_series_id}{Multiple time_series_ids can be requested as a character vector.} + +\item{approval_status}{Some of the data that you have obtained from this U.S. Geological Survey database may not have received Director's approval. Any such data values are qualified as provisional and are subject to revision. Provisional data are released on the condition that neither the USGS nor the United States Government may be held liable for any damages resulting from its use. This field reflects the approval status of each record, and is either "Approved", meaining processing review has been completed and the data is approved for publication, or "Provisional" and subject to revision. For more information about provisional data, go to \url{https://waterdata.usgs.gov/provisional-data-statement/}.} + +\item{unit_of_measure}{A human-readable description of the units of measurement associated with an observation.} + +\item{qualifier}{This field indicates any qualifiers associated with an observation, for instance if a sensor may have been impacted by ice or if values were estimated.} + +\item{value}{The value of the observation. Values are transmitted as strings in the JSON response format in order to preserve precision.} + +\item{last_modified}{The last time a record was refreshed in our database. This may happen due to regular operational processes and does not necessarily indicate anything about the measurement has changed. +You can query this field using date-times or intervals, adhering to RFC 3339, or using ISO 8601 duration objects. Intervals may be bounded or half-bounded (double-dots at start or end). +Examples: +\itemize{ +\item A date-time: "2018-02-12T23:20:50Z" +\item A bounded interval: "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z" +\item Half-bounded intervals: "2018-02-12T00:00:00Z/.." or "../2018-03-18T12:31:12Z" +\item Duration objects: "P1M" for data from the past month or "PT36H" for the last 36 hours +} + +Only features that have a \code{last_modified} that intersects the value of datetime are selected. + +See also Details below for more information.} + +\item{skipGeometry}{This parameter can be used to skip response geometries for +each feature. The returning object will be a data frame with no spatial +information. The default \code{NA} will not specify the argument in the request.} + +\item{time}{The date an observation represents. You can query this field using date-times or intervals, adhering to RFC 3339, or using ISO 8601 duration objects. Intervals may be bounded or half-bounded (double-dots at start or end). +Examples: +\itemize{ +\item A date-time: "2018-02-12T23:20:50Z" +\item A bounded interval: "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z" +\item Half-bounded intervals: "2018-02-12T00:00:00Z/.." or "../2018-03-18T12:31:12Z" +\item Duration objects: "P1M" for data from the past month or "PT36H" for the last 36 hours +} + +Only features that have a \code{time} that intersects the value of datetime are selected. If a feature has multiple temporal properties, it is the decision of the server whether only a single temporal property is used to determine the extent or all relevant temporal properties. + +See also Details below for more information.} + +\item{bbox}{Only features that have a geometry that intersects the bounding +box are selected.The bounding box is provided as four or six numbers, depending +on whether the coordinate reference system includes a vertical axis (height or +depth). Coordinates are assumed to be in crs 4326. The expected format is a numeric +vector structured: c(xmin,ymin,xmax,ymax). +Another way to think of it is c(Western-most longitude, +Southern-most latitude, Eastern-most longitude, Northern-most longitude).} + +\item{...}{Not used. Included to help differentiate official Water Data API arguments +from more seldom used, optional dataRetrieval-specific arguments.} + +\item{convertType}{logical, defaults to TRUE. +If \code{TRUE}, the function will convert the data to dates, any qualifiers to string +vector and reorder the returned data frame.} + +\item{no_paging}{logical, defaults to FALSE. +If \code{TRUE}, the data will +be requested from a native csv format. This can be dangerous because the +data will cut off at 50,000 rows without indication that more data +is available. Use \code{TRUE} with caution.} + +\item{limit}{numeric, The optional limit parameter is used to control the subset of the +selected features that should be returned in each page. The maximum allowable +limit is 50,000. It may be beneficial to set this number lower if your internet +connection is spotty. The default (\code{NA}) will set the limit to the maximum +allowable limit for the service.} + +\item{chunk_size}{Number of monitoring_location_ids to chunk requests into. +The default for functions that don't generally return long-term data records +is 250, while +the default for time series functions is +10. +Setting to \code{NA} will eliminate site chunking, giving users full control.} + +\item{attach_request}{logical, defaults to TRUE. +If set to \code{TRUE}, the full request sent to the Water Data API is attached +as an attribute to the data set.} +} +\description{ +Field measurements are physically measured values collected during a visit to the monitoring location. Field measurements consist of measurements of gage height and discharge, and readings of groundwater levels, and are primarily used as calibration readings for the automated sensors collecting continuous data. They are collected at a low frequency, and delivery of the data in WDFN may be delayed due to data processing time. +} +\details{ +You can also use a vector of length 2 for any time queries (such as time +or last_modified). The first value is the starting date (or datetime), +the second value is the ending date(or datetime). +NA's within the vector indicate a half-bound date. +For example, \code{time = c("2024-01-01", NA)} will return all data starting +at 2024-01-01. +\code{time = c(NA, "2024-01-01")} will return all data from the beginning of +the timeseries until 2024-01-01. +By default, time is assumed UTC, although time zone attributes +will be accommodated. As an example, setting \code{time = as.POSIXct(c("2021-01-01 12:00:00", +"2021-01-01 14:00"), tz = "America/New_York")} will request data that between +noon and 2pm eastern time on 2021-01-01. +All time values RETURNED from the service are UTC with the exception of +daily data, which returns time values in local dates. +} +\examples{ +\dontshow{if (is_dataRetrieval_user()) withAutoprint(\{ # examplesIf} + +\donttest{ +site <- "USGS-01435000" + +field_data_sf <- read_waterdata_latest_field_measurements(monitoring_location_id = site) + +dv_data_trim <- read_waterdata_latest_field_measurements(monitoring_location_id = site, + properties = c("monitoring_location_id", + "value", + "time")) + +field_data <- read_waterdata_latest_field_measurements(monitoring_location_id = site, + skipGeometry = TRUE) + +multi_site <- read_waterdata_latest_field_measurements(monitoring_location_id = c("USGS-01435000", + "USGS-14202650")) + +} +\dontshow{\}) # examplesIf} +} diff --git a/man/read_waterdata_monitoring_location.Rd b/man/read_waterdata_monitoring_location.Rd index 5072a644..be42815c 100644 --- a/man/read_waterdata_monitoring_location.Rd +++ b/man/read_waterdata_monitoring_location.Rd @@ -88,7 +88,7 @@ Multiple monitoring_location_ids can be requested as a character vector.} \item{site_type}{A description of the hydrologic setting of the monitoring location. A list of codes is available at \url{https://api.waterdata.usgs.gov/ogcapi/v0/collections/site-types/items}.} -\item{hydrologic_unit_code}{The United States is divided and sub-divided into successively smaller hydrologic units which are classified into four levels: regions, sub-regions, accounting units, and cataloging units. The hydrologic units are arranged within each other, from the smallest (cataloging units) to the largest (regions). Each hydrologic unit is identified by a unique hydrologic unit code (HUC) consisting of two to eight digits based on the four levels of classification in the hydrologic unit system.} +\item{hydrologic_unit_code}{The hydrologic unit code (HUC) for the monitoring location. Supports prefix matching — querying with a shorter HUC (e.g. "04") matches all locations within that hydrologic region.} \item{basin_code}{The Basin Code or "drainage basin code" is a two-digit code that further subdivides the 8-digit hydrologic-unit code. The drainage basin code is defined by the USGS State Office where the monitoring location is located.} diff --git a/man/read_waterdata_peaks.Rd b/man/read_waterdata_peaks.Rd index 830040ab..260b3654 100644 --- a/man/read_waterdata_peaks.Rd +++ b/man/read_waterdata_peaks.Rd @@ -42,7 +42,7 @@ Multiple parameter_codes can be requested as a character vector.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, time_series_id, monitoring_location_id, parameter_code, peak_id, unit_of_measure, value, last_modified, time, water_year, year, month, day, time_of_day, peak_since, qualifier. +geometry, time_series_id, monitoring_location_id, parameter_code, unit_of_measure, value, last_modified, time, water_year, year, month, day, time_of_day, peak_since, qualifier. The default (\code{NA}) will return all columns of the data.} \item{time_series_id}{A unique identifier representing a single time series. This corresponds to the \code{id} field in the \code{time-series-metadata} endpoint.} diff --git a/man/read_waterdata_ratings.Rd b/man/read_waterdata_ratings.Rd index 4b516e34..c2284e5f 100644 --- a/man/read_waterdata_ratings.Rd +++ b/man/read_waterdata_ratings.Rd @@ -57,7 +57,13 @@ and return a list of data frames with rating curve data (\code{TRUE}), or to ret just a list of available rating curve files (\code{FALSE}). Default is \code{TRUE}.} } \value{ -List of data frames which contain the requested rating curves. +List of named lists, one per requested rating file. Each element +contains: +\describe{ +\item{ratings}{Data frame of the rating curve.} +\item{metadata}{Data frame of header/value pairs parsed from the comment +attribute of the ratings file.} +} } \description{ Reads current rating table for an active USGS streamgages. More information @@ -89,15 +95,15 @@ ratings_exsa <- read_waterdata_ratings( monitoring_location_id = monitoring_location_id, file_type = "exsa") -head(ratings_exsa[["USGS-01104475.exsa.rdb"]]) -comment(ratings_exsa[["USGS-01104475.exsa.rdb"]])[1:15] +head(ratings_exsa[["USGS-01104475.exsa.rdb"]]$ratings) +ratings_exsa[["USGS-01104475.exsa.rdb"]]$metadata ratings_corr <- read_waterdata_ratings( monitoring_location_id = monitoring_location_id, file_type = "corr") -head(ratings_corr[["USGS-01104460.corr.rdb"]]) -comment(ratings_corr[["USGS-01104460.corr.rdb"]])[1:15] +head(ratings_corr[["USGS-01104460.corr.rdb"]]$ratings) +ratings_corr[["USGS-01104460.corr.rdb"]]$metadata rating_2 <- read_waterdata_ratings( monitoring_location_id = monitoring_location_id, diff --git a/man/read_waterdata_ts_meta.Rd b/man/read_waterdata_ts_meta.Rd index 3188d4b8..dd4c80cb 100644 --- a/man/read_waterdata_ts_meta.Rd +++ b/man/read_waterdata_ts_meta.Rd @@ -49,7 +49,7 @@ Multiple parameter_codes can be requested as a character vector.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, time_series_id, unit_of_measure, parameter_name, parameter_code, statistic_id, hydrologic_unit_code, state_name, last_modified, begin, end, begin_utc, end_utc, computation_period_identifier, computation_identifier, thresholds, sublocation_identifier, primary, monitoring_location_id, web_description, parameter_description, parent_time_series_id. +geometry, time_series_id, unit_of_measure, parameter_name, parameter_code, statistic_id, hydrologic_unit_code, state_name, last_modified, begin, end, begin_utc, end_utc, computation_period_identifier, computation_identifier, thresholds, sublocation_identifier, primary, monitoring_location_id, web_description, parameter_description, parent_time_series_id, data_gap_interval. The default (\code{NA}) will return all columns of the data.} \item{statistic_id}{A code corresponding to the statistic an observation represents. Example codes include 00001 (max), 00002 (min), and 00003 (mean). A complete list of codes and their descriptions can be found at \url{https://api.waterdata.usgs.gov/ogcapi/v0/collections/statistic-codes/items}. @@ -99,7 +99,7 @@ Only features that have a \code{end_utc} that intersects the value of datetime a See also Details below for more information.} -\item{hydrologic_unit_code}{The United States is divided and sub-divided into successively smaller hydrologic units which are classified into four levels: regions, sub-regions, accounting units, and cataloging units. The hydrologic units are arranged within each other, from the smallest (cataloging units) to the largest (regions). Each hydrologic unit is identified by a unique hydrologic unit code (HUC) consisting of two to eight digits based on the four levels of classification in the hydrologic unit system.} +\item{hydrologic_unit_code}{The hydrologic unit code (HUC) for the monitoring location. Supports prefix matching — querying with a shorter HUC (e.g. "04") matches all locations within that hydrologic region.} \item{state_name}{The name of the state or state equivalent in which the monitoring location is located.} diff --git a/man/read_wateruse.Rd b/man/read_wateruse.Rd index f475e0e5..96affc46 100644 --- a/man/read_wateruse.Rd +++ b/man/read_wateruse.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/read_waterdata_use.R +% Please edit documentation in R/read_wateruse.R \name{read_wateruse} \alias{read_wateruse} \title{Get USGS Water Use Data} diff --git a/tests/testthat/tests_general.R b/tests/testthat/tests_general.R index f0830ffa..54cbbd28 100644 --- a/tests/testthat/tests_general.R +++ b/tests/testthat/tests_general.R @@ -164,7 +164,7 @@ test_that("General NWIS retrievals working", { expect_equal(names(rating_curve), "USGS-01594440.base.rdb") state_rating_list <- read_waterdata_ratings( - datetime = c(Sys.Date() - 1, NA), + datetime = c(Sys.Date() - 1, as.Date(NA)), download_and_parse = FALSE ) diff --git a/tests/testthat/tests_userFriendly_fxns.R b/tests/testthat/tests_userFriendly_fxns.R index 2d05e114..b59e8fbd 100644 --- a/tests/testthat/tests_userFriendly_fxns.R +++ b/tests/testthat/tests_userFriendly_fxns.R @@ -123,11 +123,24 @@ test_that("peak, rating curves, surface-water measurements", { monitoring_location_id = siteNumber, file_type = "base" ) - expect_gt(length(comment(data[[1]])), 1) + expect_type(data, "list") + expect_length(data, 1) + + sub <- data[[1]] + expect_type(sub, "list") + expect_setequal(names(sub), c("ratings", "metadata")) # Surface meas: siteNumbers <- c("USGS-01594440", "USGS-040851325") - data <- read_waterdata_field_measurements(siteNumbers) + data <- read_waterdata_field_measurements( + monitoring_location_id = siteNumbers + ) + expect_is(data$monitoring_location_id, "character") + + # Latest Surface meas: + latest_data <- read_waterdata_latest_field_measurements( + monitoring_location_id = siteNumbers + ) expect_is(data$monitoring_location_id, "character") siteINFO_USGS <- read_waterdata_monitoring_location(