Skip to content

Commit

Permalink
refactor: make report_type's input more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Dec 19, 2024
1 parent ae205a3 commit 2f0c7f9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ importFrom(jsonlite,read_json)
importFrom(magrittr,"%>%")
importFrom(rlang,"!!!")
importFrom(rlang,"%||%")
importFrom(rlang,`%||%`)
importFrom(utils,read.table)
26 changes: 20 additions & 6 deletions R/measures.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' Get weather data from one station
#'
#' @importFrom rlang `%||%`
#'
#' @param station station ID, see riem_stations()
#' @param date_start date of start of the desired data, e.g. "2016-01-01"
Expand All @@ -8,7 +9,7 @@
#' @param data The data columns to return. The available options are: all, tmpf, dwpf, relh, drct, sknt, p01i, alti, mslp, vsby, gust, skyc1, skyc2, skyc3, skyc4, skyl1, skyl2, skyl3, skyl4, wxcodes, ice_accretion_1hr, ice_accretion_3hr, ice_accretion_6hr, peak_wind_gust, peak_wind_drct, peak_wind_time, feel, metar, snowdepth # nolint: line_length_linter
#' @param elev If TRUE, the elevation (m) of the station will be included in the output. # nolint: line_length_linter
#' @param latlon If TRUE, the latitude and longitude of the station will be included in the output. # nolint: line_length_linter
#' @param report_type The report type to query. The available options are: 1 (HFMETAR), 3 (Routine), 4 (Specials). # nolint: line_length_linter
#' @param report_type The report type to query. The available options are "hfmetar" (skipped by default), "routine", "specials". # nolint: line_length_linter
#'
#' @return a data.frame (tibble tibble) with measures,
#' the number of columns can vary from station to station,
Expand Down Expand Up @@ -75,8 +76,7 @@ riem_measures <- function(
data = "all",
elev = FALSE,
latlon = TRUE,
# skip HFMETAR by default
report_type = "3,4") {
report_type = NULL) {
if (!rlang::is_character(station, n = 1)) {
cli::cli_abort("{.arg station} must be a string.")
}
Expand All @@ -95,9 +95,23 @@ riem_measures <- function(
if (!is.logical(latlon)) {
cli::cli_abort("{.arg latlon} must be a logical (TRUE/FALSE)") # nolint: nonportable_path_linter
}
if (!rlang::is_character(report_type, n = 1)) {
cli::cli_abort("{.arg report_type} must be a string.")
}

report_type <- report_type %||% c("routine", "specials")
report_type <- tolower(report_type) # not case-sensitive
report_type <- rlang::arg_match(
report_type,
values = c("hfmetar", "routine", "specials"),
multiple = TRUE
)
report_type <- purrr::map_int(
report_type, \(x) switch(
x, # nolint: fixed_regex_linter
hfmetar = 1L,
routine = 3L,
specials = 4L
)
)
report_type <- paste(report_type, collapse = ",")

resp <- perform_riem_request(
path = "cgi-bin/request/asos.py/", # nolint: nonportable_path_linter
Expand Down
4 changes: 2 additions & 2 deletions man/riem_measures.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2f0c7f9

Please sign in to comment.