diff --git a/R/importWQP.R b/R/importWQP.R index 2a0748c3..8ce93f33 100644 --- a/R/importWQP.R +++ b/R/importWQP.R @@ -60,6 +60,10 @@ importWQP <- function(obs_url, tz = "UTC", doc <- obs_url } + last_chars <- as.character(substr(doc, nchar(doc)-1, nchar(doc))) + if(last_chars != c("\n")){ + doc <- paste0(doc, "\n") + } retval <- suppressWarnings(readr::read_delim(doc, col_types = readr::cols(.default = "c"), quote = ifelse(csv, '\"', ""), diff --git a/R/readNWISunit.R b/R/readNWISunit.R index 9f22cbba..4ec6b154 100644 --- a/R/readNWISunit.R +++ b/R/readNWISunit.R @@ -207,7 +207,7 @@ readNWISpeak <- function(siteNumbers, } - siteInfo <- readNWISsite(siteNumbers) + siteInfo <- suppressMessages(readNWISsite(siteNumbers)) siteInfo <- merge( x = unique(data[, c("agency_cd", "site_no")]), y = siteInfo, @@ -284,7 +284,7 @@ readNWISrating <- function(siteNumber, type = "base", convertType = TRUE) { attr(data, "RATING") <- Rat } - siteInfo <- readNWISsite(siteNumber) + siteInfo <- suppressMessages(readNWISsite(siteNumber)) attr(data, "siteInfo") <- siteInfo attr(data, "variableInfo") <- NULL @@ -404,7 +404,7 @@ readNWISmeas <- function(siteNumbers, } - siteInfo <- readNWISsite(siteNumbers) + siteInfo <- suppressMessages(readNWISsite(siteNumbers)) siteInfo <- merge( x = unique(data[, c("agency_cd", "site_no")]), y = siteInfo, @@ -534,7 +534,7 @@ readNWISgwl <- function(siteNumbers, data$lev_dt <- as.Date(data$lev_dt) } } - siteInfo <- readNWISsite(siteNumbers) + siteInfo <- suppressMessages(readNWISsite(siteNumbers)) siteInfo <- merge( x = unique(data[, c("agency_cd", "site_no")]), y = siteInfo, @@ -641,7 +641,7 @@ readNWISstat <- function(siteNumbers, parameterCd, startDate = "", endDate = "", convertType = convertType ) - siteInfo <- readNWISsite(siteNumbers) + siteInfo <- suppressMessages(readNWISsite(siteNumbers)) if (nrow(data) > 0) { siteInfo <- merge( diff --git a/R/readWQPdata.R b/R/readWQPdata.R index defe8693..a236f7a5 100644 --- a/R/readWQPdata.R +++ b/R/readWQPdata.R @@ -264,18 +264,20 @@ readWQPdata <- function(..., create_WQP_attributes <- function(retval, ...){ - siteInfo <- suppressWarnings(whatWQPsites(...)) + siteInfo <- suppressWarnings(whatWQPsites(..., legacy = attr(retval, "legacy"))) attr(retval, "siteInfo") <- siteInfo if(!attr(retval, "legacy")){ attr(retval, "headerInfo") <- wqp_check_status(attr(retval, "headerInfo")$`wqp-request-id`) attr(retval, "queryTime") <- as.POSIXct(attr(retval, "headerInfo")[["requestStartTime"]], - format = "%Y-%m-%dT%H:%M:%OS", tz = "GMT") + format = "%Y-%m-%dT%H:%M:%OS", tz = "UTC") } else { attr(retval, "queryTime") <- Sys.time() } + + return(retval) } diff --git a/R/readWQPqw.R b/R/readWQPqw.R index f56df96d..92998f49 100644 --- a/R/readWQPqw.R +++ b/R/readWQPqw.R @@ -93,13 +93,13 @@ readWQPqw <- function(siteNumbers, } if (!all(is.na(retval)) && !ignore_attributes) { - retval <- create_WQP_attributes(retval, siteid = sites) + retval <- suppressMessages(create_WQP_attributes(retval, siteid = sites)) } if(legacy){ wqp_message() } else { - wqp_message_beta + wqp_message_beta() } attr(retval, "url") <- url diff --git a/tests/testthat/tests_userFriendly_fxns.R b/tests/testthat/tests_userFriendly_fxns.R index 328fdb98..1f7f5ae6 100644 --- a/tests/testthat/tests_userFriendly_fxns.R +++ b/tests/testthat/tests_userFriendly_fxns.R @@ -154,6 +154,12 @@ test_that("WQP qw tests", { df2 <- readWQPqw("USGS-05427718", parameterCd = "all") expect_true(nrow(df2) > 0) + + #Empty legacy: + df3 <- readWQPqw(siteNumbers = "USGS-385032115220501", + parameterCd = "all", legacy = TRUE) + expect_true(nrow(df3) == 0) + }) context("readNWISstat tests") diff --git a/vignettes/Status.Rmd b/vignettes/Status.Rmd index 0c66867a..68b5c95c 100644 --- a/vignettes/Status.Rmd +++ b/vignettes/Status.Rmd @@ -71,7 +71,7 @@ knitr::kable(df) ## readWQPqw -The `readWQPqw()` function is generally advertised as a user-friendly function since it only works with a known list of sites, parameter codes or characterisitic names, and start/end dates. +The `readWQPqw()` function is generally advertised as a user-friendly function since it only works with a known list of sites, parameter codes or characteristic names, and start/end dates. As of `dataRetrieval` 2.7.17, this function will use the default WQX version 2 dataProfile, specified by the `legacy = TRUE` argument. Setting `legacy = FALSE` will return the WQX 3.0 "narrow" dataProfile. Keep in mind the 2.0 profiles will eventually be retired. For any more flexibility, users will need to use the `readWQPdata()` function. @@ -82,7 +82,6 @@ library(dataRetrieval) rawPcode <- readWQPqw(siteNumbers = "USGS-01594440", parameterCd = "01075", legacy = FALSE) -attr(rawPcode, "url") ``` Compared to using the WQX 2.0 legacy results: @@ -91,7 +90,6 @@ Compared to using the WQX 2.0 legacy results: rawPcode_legacy <- readWQPqw(siteNumbers = "USGS-01594440", parameterCd = "01075", legacy = TRUE) -attr(rawPcode_legacy, "url") ``` @@ -119,27 +117,23 @@ data_full <- readWQPdata(siteid = "USGS-04024315", dataProfile = "fullPhysChem", service = "ResultWQX3") ncol(data_full) -attr(data_full, "url") data_basic <- readWQPdata(siteid = "USGS-04024315", characteristicName = "pH", dataProfile = "basicPhysChem", service = "ResultWQX3") ncol(data_basic) -attr(data_basic, "url") data_narrow <- readWQPdata(siteid = "USGS-04024315", characteristicName = "pH", dataProfile = "narrow", service = "ResultWQX3") ncol(data_narrow) -attr(data_narrow, "url") data_sites <- readWQPdata(siteid = "USGS-04024315", characteristicName = "pH", service = "StationWQX3") ncol(data_sites) -attr(data_sites, "url") ``` diff --git a/vignettes/tutorial.Rmd b/vignettes/tutorial.Rmd index 04e578a4..3832655a 100644 --- a/vignettes/tutorial.Rmd +++ b/vignettes/tutorial.Rmd @@ -369,12 +369,15 @@ qw_data_sp <- readWQPqw(siteNumbers = paste0("USGS-", site), This is all great when you know your site numbers. What do you do when you don't? -There are 2 `dataRetrieval` functions that help: +There are 2 `dataRetrieval` functions that help with discover in NWIS: * `whatNWISsites` finds sites within a specified filter (quicker) * `whatNWISdata` summarizes the data within the specified filter (more information) + +And 2 functions that help with discover in WQP: + * `readWQPsummary` summarizes the data available within the WQP by year. -* `whatWQPdata` summarizes the data available within the WQP. +* `whatWQPdata` summarizes the data available within the WQP. There are several ways to specify the requests. The best way to discover how flexible the USGS web services are is to click on the links and see all of the filtering options: [http://waterservices.usgs.gov/](http://waterservices.usgs.gov/)