-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameterize key query fields in riem_measures() #48
base: main
Are you sure you want to change the base?
Changes from all commits
ee51f9e
e95c3ec
2f6a39c
695875d
ca212f2
2a5f27e
3c358b4
60d8c28
d5a7f4c
8737611
1c8a136
a75b5b9
3b082f0
12aeea5
540fb46
fe048f4
b14e790
3b8bc96
ae205a3
2f0c7f9
b3c5dd4
115a373
045b229
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ Authors@R: c( | |
comment = "The research leading to these results has received funding from the European Research Council under the ERC Grant Agreement number 336167– the CHAI Project"), | ||
person("rOpenSci", role = "fnd", | ||
comment = "https://ropensci.org/"), | ||
person("Daryl", "Herzmann", , "[email protected]", role = "ctb") | ||
person("Daryl", "Herzmann", , "[email protected]", role = "ctb"), | ||
person("Jonathan", "Elchison", email = "[email protected]", role = c("aut"), | ||
comment = c(ORCID = "0009-0004-0787-3426")) | ||
) | ||
Description: Allows to get weather data from Automated Surface Observing | ||
System (ASOS) stations (airports) in the whole world thanks to the | ||
|
@@ -40,4 +42,4 @@ Suggests: | |
xts | ||
Config/testthat/edition: 3 | ||
Encoding: UTF-8 | ||
RoxygenNote: 7.3.1 | ||
RoxygenNote: 7.3.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
#' Get weather data from one station | ||
#' | ||
#' @importFrom rlang `%||%` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
#' | ||
#' @param station station ID, see riem_stations() | ||
#' @param date_start date of start of the desired data, e.g. "2000-01-01" | ||
#' @param date_start date of start of the desired data, e.g. "2016-01-01" | ||
#' @inheritParams rlang::args_dots_empty | ||
#' @param date_end date of end of the desired data, e.g. "2016-04-22" | ||
#' @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 "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, | ||
|
@@ -63,28 +69,63 @@ | |
#' ) | ||
#' } | ||
riem_measures <- function( | ||
station = "VOHY", | ||
date_start = "2014-01-01", | ||
maelle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
date_end = as.character(Sys.Date())) { | ||
station, | ||
date_start, | ||
..., | ||
date_end = as.character(Sys.Date()), | ||
data = "all", | ||
elev = FALSE, | ||
latlon = TRUE, | ||
report_type = NULL) { | ||
if (!rlang::is_character(station, n = 1L)) { | ||
cli::cli_abort("{.arg station} must be a string.") | ||
} | ||
date_start <- format_and_check_date(date_start, "date_start") | ||
rlang::check_dots_empty() | ||
date_end <- format_and_check_date(date_end, "date_end") | ||
if (date_end < date_start) { | ||
cli::cli_abort("{.arg date_end} must be bigger than {.arg date_start}.") | ||
} | ||
if (!rlang::is_character(data, n = 1L)) { | ||
cli::cli_abort("{.arg data} must be a string.") | ||
} | ||
if (!is.logical(elev)) { | ||
cli::cli_abort("{.arg elev} must be a logical (TRUE/FALSE)") # nolint: nonportable_path_linter | ||
} | ||
if (!is.logical(latlon)) { | ||
cli::cli_abort("{.arg latlon} must be a logical (TRUE/FALSE)") # nolint: nonportable_path_linter | ||
} | ||
|
||
report_type <- report_type %||% c("routine", "specials") | ||
report_type <- tolower(report_type) # not case-sensitive | ||
report_type <- rlang::arg_match( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like your use of a map to abstract away the literals! One side effect of
It's the
|
||
report_type, | ||
values = c("hfmetar", "routine", "specials"), | ||
multiple = TRUE | ||
) | ||
report_type <- purrr::map_int( | ||
report_type, | ||
\(x) switch(x, hfmetar = 1L, routine = 3L, specials = 4L) # nolint: unnecessary_lambda_linter | ||
) | ||
report_type <- paste(report_type, collapse = ",") | ||
|
||
resp <- perform_riem_request( | ||
path = "cgi-bin/request/asos.py/", # nolint: nonportable_path_linter | ||
# query fields per https://mesonet.agron.iastate.edu/cgi-bin/request/asos.py?help # nolint: line_length_linter | ||
query = list( | ||
station = station, | ||
data = "all", | ||
data = data, | ||
elev = ifelse(elev, "yes", "no"), | ||
latlon = ifelse(latlon, "yes", "no"), | ||
year1 = lubridate::year(date_start), | ||
month1 = lubridate::month(date_start), | ||
day1 = lubridate::day(date_start), | ||
year2 = lubridate::year(date_end), | ||
month2 = lubridate::month(date_end), | ||
day2 = lubridate::day(date_end), | ||
report_type = report_type, | ||
format = "tdf", | ||
latlon = "yes", | ||
nometa = "no", | ||
tz = "UTC" | ||
) | ||
) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line duplicative of the previous? (See comment below.) I'm uncertain about the nuance of backticks vs. double-quotes.