Skip to content

Commit

Permalink
refactor: validate data
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Dec 20, 2024
1 parent bc561e2 commit 4cc6e72
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
14 changes: 13 additions & 1 deletion R/measures.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#' @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 data A vector of strings, representing 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 A vector of strings, representing report types to query.
Expand Down Expand Up @@ -98,6 +99,17 @@ riem_measures <- function(
cli::cli_abort("{.arg latlon} must be a logical (TRUE/FALSE)") # nolint: nonportable_path_linter
}

data <- rlang::arg_match(
data,
c(
"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"
)
)

report_type <- report_type %||% c("routine", "specials")
report_type <- tolower(report_type) # not case-sensitive
report_type <- rlang::arg_match(
Expand Down
3 changes: 2 additions & 1 deletion man/riem_measures.Rd

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

2 changes: 0 additions & 2 deletions tests/testthat/test-measures.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ test_that("riem_measures validates dates", {
date_end = "2013-12-01"))
})

# TODO validate 'data' against [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

test_that("riem_measures validates 'elev' param", {
# wrong type
expect_snapshot_error(riem_measures(station = "VOHY",
Expand Down

0 comments on commit 4cc6e72

Please sign in to comment.