Skip to content

Commit a43ea6f

Browse files
committed
error if epidata meta has duplicates
1 parent 737e2cb commit a43ea6f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

R/epidatacall.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,31 @@
4141
#' @return
4242
#' - For `create_epidata_call`: an `epidata_call` object
4343
#'
44+
#' @importFrom purrr map_chr
4445
create_epidata_call <- function(endpoint, params, meta = NULL,
4546
only_supports_classic = FALSE) {
4647
stopifnot(is.character(endpoint), length(endpoint) == 1)
4748
stopifnot(is.list(params))
4849
stopifnot(is.null(meta) || is.list(meta))
4950
stopifnot(is.logical(only_supports_classic), length(only_supports_classic) == 1)
51+
52+
if (length(unique(meta)) != length(meta)) {
53+
cli::cli_abort(c(
54+
"List of expected epidata fields contains duplicate entries",
55+
"i" = "duplicates in meta can cause problems parsing fetched data",
56+
"Please fix in `endpoints.R`"
57+
))
58+
}
59+
60+
meta_field_names <- map_chr(meta, ~ .x$name)
61+
if (length(meta_field_names) != length(unique(meta_field_names))) {
62+
cli::cli_abort(c(
63+
"List of expected epidata fields contains duplicate names",
64+
"i" = "duplicates in meta can cause problems parsing fetched data",
65+
"Please fix in `endpoints.R`"
66+
))
67+
}
68+
5069
if (is.null(meta)) {
5170
meta <- list()
5271
}

0 commit comments

Comments
 (0)