Skip to content

Commit 735be8c

Browse files
committed
enh: checkmate some checks
1 parent 2a7c1dc commit 735be8c

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

R/epidatacall.R

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
#' @importFrom purrr map_chr map_lgl
4545
create_epidata_call <- function(endpoint, params, meta = NULL,
4646
only_supports_classic = FALSE) {
47-
stopifnot(is.character(endpoint), length(endpoint) == 1)
48-
stopifnot(is.list(params))
49-
stopifnot(is.null(meta) || is.list(meta))
50-
stopifnot(all(map_lgl(meta, ~ inherits(.x, "EpidataFieldInfo"))))
51-
stopifnot(is.logical(only_supports_classic), length(only_supports_classic) == 1)
47+
checkmate::assert_character(endpoint, len = 1)
48+
checkmate::assert_list(params)
49+
checkmate::assert_list(meta, null.ok = TRUE)
50+
checkmate::assert_logical(only_supports_classic, len = 1)
51+
checkmate::assert_true(all(map_lgl(meta, ~ inherits(.x, "EpidataFieldInfo"))))
5252

5353
if (length(unique(meta)) != length(meta)) {
5454
cli::cli_abort(
@@ -73,6 +73,15 @@ create_epidata_call <- function(endpoint, params, meta = NULL,
7373
)
7474
}
7575

76+
# TODO: Something like this in the future? We set up the categories
77+
# but we don't actually validate them yet?
78+
# for (field in names(params)) {
79+
# value <- params[[field]]
80+
# if (meta[[field]]$type == "categorical") {
81+
# checkmate::assert_subset(value, meta[[field]]$categories)
82+
# }
83+
# }
84+
7685
if (is.null(meta)) {
7786
meta <- list()
7887
}

R/model.R

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,18 @@ create_epidata_field_info <- function(name,
132132
type,
133133
description = "",
134134
categories = c()) {
135-
stopifnot(is.character(name) && length(name) == 1)
136-
stopifnot(
137-
is.character(type) &&
138-
length(type) == 1 &&
139-
type %in% c(
140-
"text",
141-
"int",
142-
"float",
143-
"date",
144-
"epiweek",
145-
"categorical",
146-
"bool"
147-
)
148-
)
149-
stopifnot(is.character(description) && length(description) == 1)
135+
checkmate::assert_character(name, len = 1)
136+
checkmate::assert_character(type, len = 1)
137+
checkmate::assert_subset(type, c(
138+
"text",
139+
"int",
140+
"float",
141+
"date",
142+
"epiweek",
143+
"categorical",
144+
"bool"
145+
))
146+
checkmate::assert_character(description, len = 1)
150147
structure(
151148
list(
152149
name = name,

0 commit comments

Comments
 (0)