From faad5ec60791c5cb7c2bcdacd27e2926b12f3f25 Mon Sep 17 00:00:00 2001 From: Jeremy Weiss Date: Wed, 17 Jul 2024 15:20:12 -0700 Subject: [PATCH] Finish `testthat` tests for three new functions, updated documentation --- NAMESPACE | 1 + R/az_15min.R | 4 +- R/az_add_units.R | 4 +- R/az_daily.R | 2 +- R/az_heat.R | 2 +- R/az_hourly.R | 2 +- R/az_lw15min.R | 4 +- R/az_lwdaily.R | 2 +- man/az_15min.Rd | 9 +++-- man/az_add_units.Rd | 4 +- man/az_daily.Rd | 33 +++++++++------- man/az_heat.Rd | 13 ++++--- man/az_hourly.Rd | 13 ++++--- man/az_lw15min.Rd | 11 +++--- man/az_lwdaily.Rd | 67 ++++++++++++++++++++++++++++++++ tests/testthat/test-az_hourly.R | 3 +- tests/testthat/test-az_lw15min.R | 10 ++--- 17 files changed, 129 insertions(+), 55 deletions(-) create mode 100644 man/az_lwdaily.Rd diff --git a/NAMESPACE b/NAMESPACE index 1cd1648..78a985d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,5 +7,6 @@ export(az_daily) export(az_heat) export(az_hourly) export(az_lw15min) +export(az_lwdaily) importFrom(magrittr,"%>%") importFrom(rlang,.data) diff --git a/R/az_15min.R b/R/az_15min.R index 3e07909..e90c453 100755 --- a/R/az_15min.R +++ b/R/az_15min.R @@ -17,7 +17,7 @@ #' Defaults to the current date and time if left blank and `start_date_time` #' is specified. #' @details If neither `start_date_time` nor `end_date_time` are supplied, the -#' most recent date-time of data will be returned. If only `start_date_time` +#' most recent datetime of data will be returned. If only `start_date_time` #' is supplied, then `end_date_time` defaults to the current time. Supplying #' only `end_date_time` will result in an error. #' @note If `station_id` is supplied as a vector, multiple successive calls to @@ -25,7 +25,7 @@ #' the stations by leaving `station_id` blank and subsetting the resulting #' dataframe. Only the most recent 48 hours of 15-minute data are stored in #' the AZMet API. -#' @return a tibble. For units and other metadata, see +#' @return A tibble. For units and other metadata, see #' #' @seealso [az_daily()], [az_heat()], [az_hourly()], [az_lw15min()], [az_lwdaily()] #' @source diff --git a/R/az_add_units.R b/R/az_add_units.R index 996b344..29963e8 100644 --- a/R/az_add_units.R +++ b/R/az_add_units.R @@ -3,9 +3,9 @@ #' Assigns correct units to the output of `az_hourly()`, `az_daily()`, and #' `az_heat()` using the `units` package. #' -#' @param x a tibble output by [az_hourly()], [az_daily()], or [az_heat()] +#' @param x A tibble output by [az_hourly()], [az_daily()], or [az_heat()] #' -#' @return a tibble with columns of class "units" +#' @return A tibble with columns of class "units" #' @export #' #' @examples diff --git a/R/az_daily.R b/R/az_daily.R index 3e115d4..b334475 100644 --- a/R/az_daily.R +++ b/R/az_daily.R @@ -26,7 +26,7 @@ #' the stations by leaving `station_id` blank and subsetting the resulting #' dataframe. Requests for data from all stations for more than 6-12 months #' may take considerable time. -#' @return a tibble. For units and other metadata, see +#' @return A tibble. For units and other metadata, see #' #' @seealso [az_15min()], [az_heat()], [az_hourly()], [az_lw15min()], [az_lwdaily()] #' @source diff --git a/R/az_heat.R b/R/az_heat.R index 6edc152..6250e86 100644 --- a/R/az_heat.R +++ b/R/az_heat.R @@ -25,7 +25,7 @@ #' the API will be made. You may find better performance getting data for all #' the stations by leaving `station_id` blank and subsetting the resulting #' dataframe. -#' @return a tibble. For units and other metadata, see +#' @return A tibble. For units and other metadata, see #' #' @seealso [az_15min()], [az_daily()], [az_hourly()], [az_lw15min()], [az_lwdaily()] #' @source diff --git a/R/az_hourly.R b/R/az_hourly.R index 4c5e9af..c11ac3f 100644 --- a/R/az_hourly.R +++ b/R/az_hourly.R @@ -27,7 +27,7 @@ #' the stations by leaving `station_id` blank and subsetting the resulting #' dataframe. Requests for data from all stations for more than 10-15 days may #' take considerable time. -#' @return a tibble. For units and other metadata, see +#' @return A tibble. For units and other metadata, see #' #' @seealso [az_15min()], [az_daily()], [az_heat()], [az_lw15min()], [az_lwdaily()] #' @source diff --git a/R/az_lw15min.R b/R/az_lw15min.R index 50f4d45..464310d 100644 --- a/R/az_lw15min.R +++ b/R/az_lw15min.R @@ -18,7 +18,7 @@ #' Defaults to the current date and time if left blank and `start_date_time` #' is specified. #' @details If neither `start_date_time` nor `end_date_time` are supplied, the -#' most recent date-time of data will be returned. If only `start_date_time` +#' most recent datetime of data will be returned. If only `start_date_time` #' is supplied, then `end_date_time` defaults to the current time. Supplying #' only `end_date_time` will result in an error. #' @note If `station_id` is supplied as a vector, multiple successive calls to @@ -26,7 +26,7 @@ #' the stations by leaving `station_id` blank and subsetting the resulting #' dataframe. Only the most recent 48 hours of 15-minute data are stored in #' the AZMet API. -#' @return a tibble. For units and other metadata, see +#' @return A tibble. For units and other metadata, see #' #' @seealso [az_15min()], [az_daily()], [az_heat()], [az_hourly()], [az_lwdaily()] #' @source diff --git a/R/az_lwdaily.R b/R/az_lwdaily.R index bec33de..e412b21 100644 --- a/R/az_lwdaily.R +++ b/R/az_lwdaily.R @@ -26,7 +26,7 @@ #' the stations by leaving `station_id` blank and subsetting the resulting #' dataframe. Requests for data from all stations for more than 6-12 months #' may take considerable time. -#' @return a tibble. For units and other metadata, see +#' @return A tibble. For units and other metadata, see #' #' @seealso [az_15min()], [az_daily()], [az_heat()], [az_hourly()], [az_lw15min()] #' @source diff --git a/man/az_15min.Rd b/man/az_15min.Rd index 7b0d9ad..d7182a2 100644 --- a/man/az_15min.Rd +++ b/man/az_15min.Rd @@ -26,16 +26,17 @@ Defaults to the current date and time if left blank and \code{start_date_time} is specified.} } \value{ -a tibble. For units and other metadata, see +A tibble. For units and other metadata, see \url{https://azmet.arizona.edu/about} } \description{ Retrieves 15-minute data from the AZMet (Arizona Meteorological Network) API. -For a list of weather stations and their locations see \link{station_info}. +For a list of weather stations and their locations see \link{station_info}, or +visit https://azmet.arizona.edu/about. } \details{ If neither \code{start_date_time} nor \code{end_date_time} are supplied, the -most recent date-time of data will be returned. If only \code{start_date_time} +most recent datetime of data will be returned. If only \code{start_date_time} is supplied, then \code{end_date_time} defaults to the current time. Supplying only \code{end_date_time} will result in an error. } @@ -61,5 +62,5 @@ az_15min(start_date_time = "2022-09-25 01:00:00", end_date_time = "2022-09-25 07 } } \seealso{ -\code{\link[=az_daily]{az_daily()}}, \code{\link[=az_heat]{az_heat()}}, \code{\link[=az_hourly]{az_hourly()}}, \code{\link[=az_lw15min]{az_lw15min()}} +\code{\link[=az_daily]{az_daily()}}, \code{\link[=az_heat]{az_heat()}}, \code{\link[=az_hourly]{az_hourly()}}, \code{\link[=az_lw15min]{az_lw15min()}}, \code{\link[=az_lwdaily]{az_lwdaily()}} } diff --git a/man/az_add_units.Rd b/man/az_add_units.Rd index 8bd8291..81435c4 100644 --- a/man/az_add_units.Rd +++ b/man/az_add_units.Rd @@ -7,10 +7,10 @@ az_add_units(x) } \arguments{ -\item{x}{a tibble output by \code{\link[=az_hourly]{az_hourly()}}, \code{\link[=az_daily]{az_daily()}}, or \code{\link[=az_heat]{az_heat()}}} +\item{x}{A tibble output by \code{\link[=az_hourly]{az_hourly()}}, \code{\link[=az_daily]{az_daily()}}, or \code{\link[=az_heat]{az_heat()}}} } \value{ -a tibble with columns of class "units" +A tibble with columns of class "units" } \description{ Assigns correct units to the output of \code{az_hourly()}, \code{az_daily()}, and diff --git a/man/az_daily.Rd b/man/az_daily.Rd index 94ddc5c..036ed70 100644 --- a/man/az_daily.Rd +++ b/man/az_daily.Rd @@ -4,37 +4,41 @@ \alias{az_daily} \title{Retrieve Daily Weather Data from AZMET} \source{ -\url{https://ag.arizona.edu/azmet/} +\url{https://azmet.arizona.edu/} } \usage{ az_daily(station_id = NULL, start_date = NULL, end_date = NULL) } \arguments{ \item{station_id}{station ID can be supplied as numeric vector (e.g. -\code{station_id = c(8, 37)}) or as character vector with the prefix "az" and 2 -digits (e.g. \code{station_id = c("az08", "az37")}) If left blank data for all -stations will be returned} +\code{station_id = c(8, 37)}) or as character vector with the prefix "az" and +two digits (e.g. \code{station_id = c("az08", "az37")}). If left blank, data for all +stations will be returned.} \item{start_date}{A length-1 vector of class Date, POSIXct, or character in -YYYY-MM-DD format. Will be rounded \strong{down} to the nearest day if more -precision is supplied.} +YYYY-MM-DD format. Will be rounded \strong{down} to the nearest day if more +precision is supplied. Defaults to the day before the current date (i.e., +the most recent complete day) if left blank.} \item{end_date}{A length-1 vector of class Date, POSIXct, or character in -YYYY-MM-DD format. Will be rounded \strong{down} to the nearest day if more -precision is supplied. Defaults to the current date if left blank.} +YYYY-MM-DD format. Will be rounded \strong{down} to the nearest day if more +precision is supplied. Defaults to the day before the current date (i.e., +the most recent complete day) if left blank.} } \value{ -a tibble. For units and other metadata, see -\url{https://ag.arizona.edu/azmet/raw2003.htm} +A tibble. For units and other metadata, see +\url{https://azmet.arizona.edu/about} } \description{ Retrieves daily data from the Arizona Meteorological Network API. For a list -of weather stations and their locations see \link{station_info}. +of weather stations and their locations see \link{station_info}, or visit +https://azmet.arizona.edu/about. } \details{ If neither \code{start_date} nor \code{end_date} are supplied, the most recent -day of data will be returned. If only \code{start_date} is supplied, then the -end date defaults to the current date. Supplying only \code{end_date} will +day of data will be returned. If only \code{start_date} is supplied, then the +end date defaults to the day before the current date (i.e., +the most recent complete day). Supplying only \code{end_date} will result in an error. } \note{ @@ -57,8 +61,7 @@ az_daily(station_id = c("az01", "az02")) az_daily(start_date = "2022-09-25") az_daily(start_date = "2022-09-25", end_date = "2022-09-26") } - } \seealso{ -\code{\link[=az_15min]{az_15min()}}, \code{\link[=az_heat]{az_heat()}}, \code{\link[=az_hourly]{az_hourly()}}, \code{\link[=az_lw15min]{az_lw15min()}} +\code{\link[=az_15min]{az_15min()}}, \code{\link[=az_heat]{az_heat()}}, \code{\link[=az_hourly]{az_hourly()}}, \code{\link[=az_lw15min]{az_lw15min()}}, \code{\link[=az_lwdaily]{az_lwdaily()}} } diff --git a/man/az_heat.Rd b/man/az_heat.Rd index effa42c..6d02d8c 100644 --- a/man/az_heat.Rd +++ b/man/az_heat.Rd @@ -4,7 +4,7 @@ \alias{az_heat} \title{Retrieve Accumulated Heat Units and Evapotranspiration} \source{ -\url{https://ag.arizona.edu/azmet/} +\url{https://azmet.arizona.edu/} } \usage{ az_heat(station_id = NULL, start_date = NULL, end_date = NULL) @@ -26,14 +26,15 @@ an \code{end_date} is supplied, then data will be cumulative from the start of the year of \code{end_date}.} } \value{ -a tibble. For units and other metadata, see -\url{https://ag.arizona.edu/azmet/raw2003.htm} +A tibble. For units and other metadata, see +\url{https://azmet.arizona.edu/about} } \description{ Retrieves accumulated heat units and reference evapotranspiration units from -the Arizona Meteorological Network API. By default, returned values are +the Arizona Meteorological Network API. By default, returned values are cumulative since January 1 of the current year. For a list of weather -stations and their locations see \link{station_info}. +stations and their locations see \link{station_info}, or visit +https://azmet.arizona.edu/about. } \details{ Unlike \code{\link[=az_daily]{az_daily()}}, only one row of data per station is returned, @@ -67,5 +68,5 @@ az_heat(end_date = paste(yr, "03", "31", sep = "-")) } \seealso{ -\code{\link[=az_15min]{az_15min()}}, \code{\link[=az_daily]{az_daily()}}, \code{\link[=az_hourly]{az_hourly()}}, \code{\link[=az_lw15min]{az_lw15min()}} +\code{\link[=az_15min]{az_15min()}}, \code{\link[=az_daily]{az_daily()}}, \code{\link[=az_hourly]{az_hourly()}}, \code{\link[=az_lw15min]{az_lw15min()}}, \code{\link[=az_lwdaily]{az_lwdaily()}} } diff --git a/man/az_hourly.Rd b/man/az_hourly.Rd index 9519ea6..72e70f7 100644 --- a/man/az_hourly.Rd +++ b/man/az_hourly.Rd @@ -4,7 +4,7 @@ \alias{az_hourly} \title{Retrieve Hourly Weather Data} \source{ -\url{https://ag.arizona.edu/azmet/} +\url{https://azmet.arizona.edu/} } \usage{ az_hourly(station_id = NULL, start_date_time = NULL, end_date_time = NULL) @@ -12,7 +12,7 @@ az_hourly(station_id = NULL, start_date_time = NULL, end_date_time = NULL) \arguments{ \item{station_id}{station ID can be supplied as numeric vector (e.g. \code{station_id = c(8, 37)}) or as character vector with the prefix "az" and 2 -digits (e.g. \code{station_id = c("az08", "az37")}) If left blank data for all +digits (e.g. \code{station_id = c("az08", "az37")}) If left blank, data for all stations will be returned} \item{start_date_time}{A length-1 vector of class POSIXct or character in @@ -28,12 +28,13 @@ Defaults to the current date and time if left blank and \code{start_date_time} is specified.} } \value{ -a tibble. For units and other metadata, see -\url{https://ag.arizona.edu/azmet/raw2003.htm} +A tibble. For units and other metadata, see +\url{https://azmet.arizona.edu/about} } \description{ Retrieves hourly weather data from the Arizona Meteorological Network API. -For a list of weather stations and their locations see \link{station_info}. +For a list of weather stations and their locations see \link{station_info}, or +visit https://azmet.arizona.edu/about. } \details{ If neither \code{start_date_time} nor \code{end_date_time} are supplied, the @@ -64,5 +65,5 @@ az_hourly(start_date_time = "2022-09-25 01", end_date = "2022-09-25 20") } \seealso{ -\code{\link[=az_15min]{az_15min()}}, \code{\link[=az_daily]{az_daily()}}, \code{\link[=az_heat]{az_heat()}}, \code{\link[=az_lw15min]{az_lw15min()}} +\code{\link[=az_15min]{az_15min()}}, \code{\link[=az_daily]{az_daily()}}, \code{\link[=az_heat]{az_heat()}}, \code{\link[=az_lw15min]{az_lw15min()}}, \code{\link[=az_lwdaily]{az_lwdaily()}} } diff --git a/man/az_lw15min.Rd b/man/az_lw15min.Rd index 4d4befe..3933e8b 100644 --- a/man/az_lw15min.Rd +++ b/man/az_lw15min.Rd @@ -26,17 +26,18 @@ Defaults to the current date and time if left blank and \code{start_date_time} is specified.} } \value{ -a tibble. For units and other metadata, see +A tibble. For units and other metadata, see \url{https://azmet.arizona.edu/about} } \description{ Retrieves 15-minute leaf-wetness data from the AZMet (Arizona Meteorological -Network) API. Currently, these data only are available from stations in the -Yuma area. For a list of stations and their locations see \link{station_info}. +Network) API. Currently, these data only are available from weather stations +in the Yuma area. For a list of stations and their locations see +\link{station_info}, or visit https://azmet.arizona.edu/about. } \details{ If neither \code{start_date_time} nor \code{end_date_time} are supplied, the -most recent date-time of data will be returned. If only \code{start_date_time} +most recent datetime of data will be returned. If only \code{start_date_time} is supplied, then \code{end_date_time} defaults to the current time. Supplying only \code{end_date_time} will result in an error. } @@ -62,5 +63,5 @@ az_lw15min(start_date_time = "2022-09-25 01:00:00", end_date_time = "2022-09-25 } } \seealso{ -\code{\link[=az_15min]{az_15min()}}, \code{\link[=az_daily]{az_daily()}}, \code{\link[=az_heat]{az_heat()}}, \code{\link[=az_hourly]{az_hourly()}} +\code{\link[=az_15min]{az_15min()}}, \code{\link[=az_daily]{az_daily()}}, \code{\link[=az_heat]{az_heat()}}, \code{\link[=az_hourly]{az_hourly()}}, \code{\link[=az_lwdaily]{az_lwdaily()}} } diff --git a/man/az_lwdaily.Rd b/man/az_lwdaily.Rd new file mode 100644 index 0000000..be7f58c --- /dev/null +++ b/man/az_lwdaily.Rd @@ -0,0 +1,67 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/az_lwdaily.R +\name{az_lwdaily} +\alias{az_lwdaily} +\title{Retrieve Daily Leaf Wetness Data from AZMet} +\source{ +\url{https://azmet.arizona.edu/} +} +\usage{ +az_lwdaily(station_id = NULL, start_date = NULL, end_date = NULL) +} +\arguments{ +\item{station_id}{station ID can be supplied as numeric vector (e.g. +\code{station_id = c(8, 37)}) or as character vector with the prefix "az" and +two digits (e.g. \code{station_id = c("az08", "az37")}). If left blank, data for +all stations will be returned.} + +\item{start_date}{A length-1 vector of class Date, POSIXct, or character in +YYYY-MM-DD format. Will be rounded \strong{down} to the nearest day if more +precision is supplied. Defaults to the day before the current date (i.e., +the most recent complete day) if left blank.} + +\item{end_date}{A length-1 vector of class Date, POSIXct, or character in +YYYY-MM-DD format. Will be rounded \strong{down} to the nearest day if more +precision is supplied. Defaults to the day before the current date (i.e., +the most recent complete day) if left blank.} +} +\value{ +A tibble. For units and other metadata, see +\url{https://azmet.arizona.edu/about} +} +\description{ +Retrieves daily leaf wetness data from the Arizona Meteorological Network +API. Currently, these data only are available from weather stations in the +Yuma area. For a list of stations and their locations see \link{station_info}, or +visit https://azmet.arizona.edu/about. +} +\details{ +If neither \code{start_date} nor \code{end_date} are supplied, the most recent +day of data will be returned. If only \code{start_date} is supplied, then the +end date defaults to the day before the current date (i.e., the most recent +complete day). Supplying only \code{end_date} will result in an error. +} +\note{ +If \code{station_id} is supplied as a vector, multiple successive calls to +the API will be made. You may find better performance getting data for all +the stations by leaving \code{station_id} blank and subsetting the resulting +dataframe. Requests for data from all stations for more than 6-12 months +may take considerable time. +} +\examples{ +\dontrun{ +# Most recent data for all stations: +az_lwdaily() + +# Specify stations: +az_lwdaily(station_id = c(1, 2)) +az_lwdaily(station_id = c("az01", "az02")) + +# Specify dates: +az_lwdaily(start_date = "2022-09-25") +az_lwdaily(start_date = "2022-09-25", end_date = "2022-09-26") +} +} +\seealso{ +\code{\link[=az_15min]{az_15min()}}, \code{\link[=az_daily]{az_daily()}}, \code{\link[=az_heat]{az_heat()}}, \code{\link[=az_hourly]{az_hourly()}}, \code{\link[=az_lw15min]{az_lw15min()}} +} diff --git a/tests/testthat/test-az_hourly.R b/tests/testthat/test-az_hourly.R index 6cd7544..57a0ab5 100644 --- a/tests/testthat/test-az_hourly.R +++ b/tests/testthat/test-az_hourly.R @@ -58,7 +58,7 @@ test_that("start=NULL, end=NULL works as expected", { az_hourly( station_id = "az01" ) - }, glue::glue("Querying most recent hour of data")) + }, glue::glue("Querying most recent hour of data ...")) expect_equal(nrow(null_null), 1) #could be that current hour hasn't hit API yet. @@ -101,4 +101,3 @@ test_that("start as date only is rounded correctly", { ) expect_equal(min(date_null$date_datetime), start_actual) }) - diff --git a/tests/testthat/test-az_lw15min.R b/tests/testthat/test-az_lw15min.R index 3187ede..8c97b7c 100644 --- a/tests/testthat/test-az_lw15min.R +++ b/tests/testthat/test-az_lw15min.R @@ -36,7 +36,7 @@ test_that("data is in correct format", { ) ) expect_type(res_default$meta_station_name, "character") - expect_type(res_default$precip_total_mm, "double") + expect_type(res_default$temp_wetbulb_meanC, "double") expect_s3_class(res_default$datetime, "POSIXct") }) @@ -54,7 +54,7 @@ test_that("requests with 23:59:59 work", { h <- suppressWarnings( az_lw15min( - station_id = "az01", + station_id = "az02", start_date_time = paste0(lubridate::today(tzone = "America/Phoenix") - 1, " 23:00"), end_date_time = paste0(lubridate::today(tzone = "America/Phoenix") - 1, " 23:59") ) @@ -67,10 +67,10 @@ test_that("start=NULL, end=NULL works as expected", { null_null <- suppressWarnings( az_lw15min( - station_id = "az01" + station_id = "az02" ) ) - }, glue::glue("Querying most recent datetime of 15-minute data ...")) + }, glue::glue("Querying most recent datetime of leaf wetness 15-minute data ...")) expect_equal(nrow(null_null), 1) }) @@ -92,7 +92,7 @@ test_that("start as date only is rounded correctly", { start_ymd <- suppressWarnings( az_lw15min( - station_id = "az01", + station_id = "az02", start_date_time = start_input, end_date_time = end_hour )