Skip to content

Validate version argument (fix NA crash)#6

Open
karstenm1987 wants to merge 1 commit intomainfrom
fix/version-na-validation
Open

Validate version argument (fix NA crash)#6
karstenm1987 wants to merge 1 commit intomainfrom
fix/version-na-validation

Conversation

@karstenm1987
Copy link
Copy Markdown

Tracked upstream at Global-Macro-Database-Internal#413. Same filter applied to the recent Stata PR: fix actual bugs, skip nice-to-haves.

Bug

gmd(version = NA) crashed with the cryptic R-level error "missing value where TRUE/FALSE needed". Root cause at R/gmd.R:263:

if (!is.null(version) && tolower(version) == "list") { ... }

With version = NA, tolower(NA) returns NA, NA == "list" returns NA, and if (NA) is an error. Same failure mode for version = 2025 (numeric) or a multi-element character vector.

Fix

Reject those inputs at the top of the version-check block with a clear message that names the argument.

Verified

> gmd(version = NA,               country = "USA", variables = "rGDP")
Error: `version` must be a single non-NA string (e.g. "2025_09"), "current", or "list".
> gmd(version = NA_character_,    country = "USA", variables = "rGDP")
Error: `version` must be a single non-NA string (e.g. "2025_09"), "current", or "list".
> gmd(version = c("2025_09","2026_03"), country = "USA", variables = "rGDP")
Error: `version` must be a single non-NA string (...).
> gmd(version = 2025,             country = "USA", variables = "rGDP")
Error: `version` must be a single non-NA string (...).

# Regressions — all still work:
> gmd(version = "2025_09", country = "USA", variables = "rGDP")   # 242 rows
> gmd(version = "current", country = "USA", variables = "rGDP")   # 241 rows
> gmd(version = "list")                                            # prints list
> gmd(country = "USA", variables = "rGDP")                         # 241 rows (NULL default)

Out of scope

Other issues catalogued in #413 (double "Error:" prefix, case-sensitivity inconsistency across country/variables/sources, iso=TRUE warning vs error, empty-vector handling, dependency cleanup, start_year/end_year not implemented) are UX/consistency issues rather than functional bugs, kept for separate PRs.

Also note: the listed-but-404 versions on S3 (2025_01/03/05/06/08) are a release-pipeline issue and not fixable here.

`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) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants