diff --git a/.lintr b/.lintr index 601ece9..2987445 100644 --- a/.lintr +++ b/.lintr @@ -1,3 +1,2 @@ -linters:with_defaults(camel_case_linter = NULL, - object_length_linter(50)) -exclusions: list("tests/testthat.R", "tests/testthat/test-measures.R", "tests/testthat/test-networks.R", "tests/testthat/test-stations.R") +linters: lintr::linters_with_tags(tags = NULL) +encoding: "UTF-8" diff --git a/R/measures.R b/R/measures.R index 0ddb05a..9ab2038 100644 --- a/R/measures.R +++ b/R/measures.R @@ -5,7 +5,8 @@ #' @param date_start date of start of the desired data, e.g. "2000-01-01" #' @param date_end date of end of the desired data, e.g. "2016-04-22" #' -#' @return a data.frame (tibble tibble) with measures, the number of columns can vary from station to station, +#' @return a data.frame (tibble tibble) with measures, +#' the number of columns can vary from station to station, #' but possible variables are #' \itemize{ #' \item station: three or four character site identifier @@ -15,7 +16,12 @@ #' \item relh: Relative Humidity in % #' \item drct: Wind Direction in degrees from north #' \item sknt: Wind Speed in knots -#' \item p01i: One hour precipitation for the period from the observation time to the time of the previous hourly precipitation reset. This varies slightly by site. Values are in inches. This value may or may not contain frozen precipitation melted by some device on the sensor or estimated by some other means. Unfortunately, we do not know of an authoritative database denoting which station has which sensor. +#' \item p01i: One hour precipitation for the period from the observation time +#' to the time of the previous hourly precipitation reset. +#' This varies slightly by site. Values are in inches. +#' This value may or may not contain frozen precipitation melted by some device +#' on the sensor or estimated by some other means. Unfortunately, we do not know +#' of an authoritative database denoting which station has which sensor. #' \item alti: Pressure altimeter in inches #' \item mslp: Sea Level Pressure in millibar #' \item vsby: Visibility in miles @@ -29,24 +35,32 @@ #' \item skyl3: Sky Level 3 Altitude in feet #' \item skyl4: Sky Level 4 Altitude in feet #' \item presentwx: Present Weather Codes (space seperated), -#' see e.g. Chapter 8 of [this manual](https://www.ofcm.gov/publications/fmh/FMH1/FMH1.pdf) for further explanations. +#' see e.g. Chapter 8 of [this manual](https://www.ofcm.gov/publications/fmh/FMH1/FMH1.pdf) for further explanations.# nolint: line_length_linter #' \item feel: Apparent Temperature (Wind Chill or Heat Index) in degF #' \item ice_accretion_1hr: Ice Accretion over 1 Hour in inch #' \item ice_accretion_3hr: Ice Accretion over 3 Hour in inch #' \item ice_accretion_6hr: Ice Accretion over 6 Hour in inch #' \item relh: Relative Humidity in % #' \item metar: unprocessed reported observation in METAR format -#' \item peak_wind_gust: Wind gust in knots from the METAR PK WND remark, this value may be different than the value found in the gust field. The gust field is derived from the standard METAR wind report. -#' \item peak_wind_drct: The wind direction in degrees North denoted in the METAR PK WND remark. -#' \item peak_wind_time: The timestamp of the PK WND value in the same timezone as the valid field and controlled by the tz parameter. +#' \item peak_wind_gust: Wind gust in knots from the METAR PK WND remark, +#' this value may be different than the value found in the gust field. +#' The gust field is derived from the standard METAR wind report. +#' \item peak_wind_drct: The wind direction in degrees North denoted +#' in the METAR PK WND remark. +#' \item peak_wind_time: The timestamp of the PK WND value in the same timezone +#' as the valid field and controlled by the tz parameter. #' } -#' @details The data is queried through \url{https://mesonet.agron.iastate.edu/request/download.phtml}. +#' @details The data is queried through \url{https://mesonet.agron.iastate.edu/request/download.phtml}.# nolint: line_length_linter #' @export #' #' @examples #' \dontrun{ -#' riem_measures(station = "VOHY", date_start = "2016-01-01", date_end = "2016-04-22") +#' riem_measures( +#' station = "VOHY", +#' date_start = "2016-01-01", +#' date_end = "2016-04-22" +#' ) #' } riem_measures <- function( station = "VOHY", @@ -59,7 +73,7 @@ riem_measures <- function( } resp <- perform_riem_request( - path = "cgi-bin/request/asos.py/", + path = "cgi-bin/request/asos.py/", # nolint: nonportable_path_linter query = list( station = station, data = "all", @@ -79,34 +93,34 @@ riem_measures <- function( content <- httr2::resp_body_string(resp) - col.names <- read.table( + col_names <- read.table( text = content, - skip = 5, - nrows = 1, + skip = 5L, + nrows = 1L, na.strings = c("", "NA", "M"), sep = "\t", stringsAsFactors = FALSE ) %>% t() %>% as.character() - col.names <- gsub(" ", "", col.names) + col_names <- gsub(" ", "", col_names, fixed = TRUE) result <- read.table( text = content, - skip = 6, - col.names = col.names, + skip = 6L, + col.names = col_names, na.strings = c("", "NA", "M"), sep = "\t", stringsAsFactors = FALSE, fill = TRUE ) - if (nrow(result) == 0) { + if (nrow(result) == 0L) { cli::cli_warn("No results for this query.") return(NULL) } - result$valid <- lubridate::ymd_hm(result$valid) + result$valid <- lubridate::ymd_hm(result$valid) # nolint: extraction_operator_linter tibble::as_tibble(result) } diff --git a/R/networks.R b/R/networks.R index a57852f..58ed8c1 100644 --- a/R/networks.R +++ b/R/networks.R @@ -1,6 +1,7 @@ #' Get ASOS and AWOS networks #' -#' @return a data.frame (tibble tibble) with the names and codes of available networks. +#' @return a data.frame (tibble tibble) with the names and codes of +#' available networks. #' @export #' #' @examples @@ -8,7 +9,7 @@ #' riem_networks() #' } riem_networks <- function() { - resp <- perform_riem_request(path = "api/1/networks.json") + resp <- perform_riem_request(path = "api/1/networks.json") # nolint: nonportable_path_linter httr2::resp_check_status(resp) @@ -19,7 +20,7 @@ riem_networks <- function() { name = purrr::map_chr(content[["data"]], "name") ) - is_asos_or_awos <- grepl("A[SW]OS", networks_data$code) + is_asos_or_awos <- grepl("A[SW]OS", networks_data[["code"]]) networks_data[is_asos_or_awos, ] } diff --git a/R/stations.R b/R/stations.R index 965eda1..fcd59c7 100644 --- a/R/stations.R +++ b/R/stations.R @@ -1,9 +1,12 @@ #' Get stations of an ASOS network #' #' -#' @param network A single network code, see riem_networks() for finding the code corresponding to a name. -#' @return a data.frame (tibble tibble) with the id, name, longitude (lon) and latitude (lat) of each station in the network. -#' @details You can see a map of stations in a network at \url{https://mesonet.agron.iastate.edu/request/download.phtml}. +#' @param network A single network code, see riem_networks() for finding +#' the code corresponding to a name. +#' @return a data.frame (tibble tibble) with the id, name, longitude (lon) and +#' latitude (lat) of each station in the network. +#' @details You can see a map of stations in a network at +#' \url{https://mesonet.agron.iastate.edu/request/download.phtml}. #' @export #' #' @examples @@ -11,11 +14,11 @@ #' riem_stations(network = "IN__ASOS") #' } riem_stations <- function(network) { - valid_network_code <- (network %in% riem_networks()$code) + valid_network_code <- (network %in% riem_networks()$code) # nolint: extraction_operator_linter if (!valid_network_code) error_invalid_network(network) resp <- perform_riem_request( - path = sprintf("api/1/network/%s.json", network) + path = sprintf("api/1/network/%s.json", network) # nolint: nonportable_path_linter ) httr2::resp_check_status(resp) @@ -27,8 +30,8 @@ riem_stations <- function(network) { results <- results[, !names(results) == "combo"] - results$lon <- as.numeric(results$longitude) - results$lat <- as.numeric(results$latitude) + results$lon <- as.numeric(results$longitude) # nolint: extraction_operator_linter + results$lat <- as.numeric(results$latitude) # nolint: extraction_operator_linter return(results) } @@ -36,7 +39,7 @@ riem_stations <- function(network) { error_invalid_network <- function(network) { cli::cli_abort( c( - x = sprintf("{.arg network} ({.value {network}}) is an invalid network code."), + x = sprintf("{.arg network} ({.value {network}}) is an invalid network code."), # nolint: line_length_linter i = "See {.fun riem_networks} for valid codes." ) ) diff --git a/R/utils.R b/R/utils.R index c9fd402..901c580 100644 --- a/R/utils.R +++ b/R/utils.R @@ -10,6 +10,6 @@ perform_riem_request <- function(path, query = NULL) { httr2::req_url_path_append(path) %>% httr2::req_url_query(!!!query) %>% httr2::req_user_agent("riem (https://docs.ropensci.org/riem)") %>% - httr2::req_retry(max_tries = 3, max_seconds = 120) %>% + httr2::req_retry(max_tries = 3L, max_seconds = 120L) %>% httr2::req_perform() } diff --git a/man/riem_measures.Rd b/man/riem_measures.Rd index 2cb9673..c6f980a 100644 --- a/man/riem_measures.Rd +++ b/man/riem_measures.Rd @@ -18,7 +18,8 @@ riem_measures( \item{date_end}{date of end of the desired data, e.g. "2016-04-22"} } \value{ -a data.frame (tibble tibble) with measures, the number of columns can vary from station to station, +a data.frame (tibble tibble) with measures, +the number of columns can vary from station to station, but possible variables are \itemize{ \item station: three or four character site identifier @@ -28,7 +29,12 @@ but possible variables are \item relh: Relative Humidity in % \item drct: Wind Direction in degrees from north \item sknt: Wind Speed in knots -\item p01i: One hour precipitation for the period from the observation time to the time of the previous hourly precipitation reset. This varies slightly by site. Values are in inches. This value may or may not contain frozen precipitation melted by some device on the sensor or estimated by some other means. Unfortunately, we do not know of an authoritative database denoting which station has which sensor. +\item p01i: One hour precipitation for the period from the observation time +to the time of the previous hourly precipitation reset. +This varies slightly by site. Values are in inches. +This value may or may not contain frozen precipitation melted by some device +on the sensor or estimated by some other means. Unfortunately, we do not know + of an authoritative database denoting which station has which sensor. \item alti: Pressure altimeter in inches \item mslp: Sea Level Pressure in millibar \item vsby: Visibility in miles @@ -42,26 +48,34 @@ but possible variables are \item skyl3: Sky Level 3 Altitude in feet \item skyl4: Sky Level 4 Altitude in feet \item presentwx: Present Weather Codes (space seperated), - see e.g. Chapter 8 of [this manual](https://www.ofcm.gov/publications/fmh/FMH1/FMH1.pdf) for further explanations. + see e.g. Chapter 8 of [this manual](https://www.ofcm.gov/publications/fmh/FMH1/FMH1.pdf) for further explanations.# nolint: line_length_linter \item feel: Apparent Temperature (Wind Chill or Heat Index) in degF \item ice_accretion_1hr: Ice Accretion over 1 Hour in inch \item ice_accretion_3hr: Ice Accretion over 3 Hour in inch \item ice_accretion_6hr: Ice Accretion over 6 Hour in inch \item relh: Relative Humidity in % \item metar: unprocessed reported observation in METAR format -\item peak_wind_gust: Wind gust in knots from the METAR PK WND remark, this value may be different than the value found in the gust field. The gust field is derived from the standard METAR wind report. -\item peak_wind_drct: The wind direction in degrees North denoted in the METAR PK WND remark. -\item peak_wind_time: The timestamp of the PK WND value in the same timezone as the valid field and controlled by the tz parameter. +\item peak_wind_gust: Wind gust in knots from the METAR PK WND remark, +this value may be different than the value found in the gust field. +The gust field is derived from the standard METAR wind report. +\item peak_wind_drct: The wind direction in degrees North denoted +in the METAR PK WND remark. +\item peak_wind_time: The timestamp of the PK WND value in the same timezone +as the valid field and controlled by the tz parameter. } } \description{ Get weather data from one station } \details{ -The data is queried through \url{https://mesonet.agron.iastate.edu/request/download.phtml}. +The data is queried through \url{https://mesonet.agron.iastate.edu/request/download.phtml}.# nolint: line_length_linter } \examples{ \dontrun{ -riem_measures(station = "VOHY", date_start = "2016-01-01", date_end = "2016-04-22") +riem_measures( + station = "VOHY", + date_start = "2016-01-01", + date_end = "2016-04-22" +) } } diff --git a/man/riem_networks.Rd b/man/riem_networks.Rd index 171e619..72998ae 100644 --- a/man/riem_networks.Rd +++ b/man/riem_networks.Rd @@ -7,7 +7,8 @@ riem_networks() } \value{ -a data.frame (tibble tibble) with the names and codes of available networks. +a data.frame (tibble tibble) with the names and codes of +available networks. } \description{ Get ASOS and AWOS networks diff --git a/man/riem_stations.Rd b/man/riem_stations.Rd index f225371..5f64584 100644 --- a/man/riem_stations.Rd +++ b/man/riem_stations.Rd @@ -7,16 +7,19 @@ riem_stations(network) } \arguments{ -\item{network}{A single network code, see riem_networks() for finding the code corresponding to a name.} +\item{network}{A single network code, see riem_networks() for finding +the code corresponding to a name.} } \value{ -a data.frame (tibble tibble) with the id, name, longitude (lon) and latitude (lat) of each station in the network. +a data.frame (tibble tibble) with the id, name, longitude (lon) and +latitude (lat) of each station in the network. } \description{ Get stations of an ASOS network } \details{ -You can see a map of stations in a network at \url{https://mesonet.agron.iastate.edu/request/download.phtml}. +You can see a map of stations in a network at +\url{https://mesonet.agron.iastate.edu/request/download.phtml}. } \examples{ \dontrun{