From 09f62f9093a0ed5c092ba7d20461775a80eff8fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karsten=20M=C3=BCller?= <52325194+karstenm1987@users.noreply.github.com> Date: Sun, 19 Apr 2026 09:33:43 +0200 Subject: [PATCH] Validate version argument (reject NA, non-character, non-scalar) `gmd(version = NA)` previously crashed with the cryptic R-level "missing value where TRUE/FALSE needed" because `NA` propagated into `tolower(version) == "list"`, where the comparison yields `NA` and `if (NA)` is an error. Same error for `version = 2025`, or a multi-element character vector. Reject those inputs up-front with a clear message naming the argument. Internal issue: KMueller-Lab/Global-Macro-Database-Internal#413 Co-Authored-By: Claude Opus 4.7 (1M context) --- R/gmd.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/R/gmd.R b/R/gmd.R index 6c1bfc3..6ad4828 100644 --- a/R/gmd.R +++ b/R/gmd.R @@ -256,6 +256,14 @@ gmd <- function(variables = NULL, country = NULL, version = NULL, # ============================================================================ # Version check (S3 first, GitHub fallback) # ============================================================================ + + # Reject NA / non-character version early so it doesn't propagate into + # `tolower(version) == "list"` below (which would error with the cryptic + # "missing value where TRUE/FALSE needed") + if (!is.null(version) && (!is.character(version) || length(version) != 1 || is.na(version))) { + stop("`version` must be a single non-NA string (e.g. \"2025_09\"), \"current\", or \"list\".") + } + versions_df <- .gmd_load_versions_df() available_versions <- sort(unique(versions_df$versions), decreasing = TRUE) current_version <- available_versions[1]