Robustness fixes for the R package (#318): version/input validation, case-insensitive variables, year filtering, httr2#7
Open
Yicheng-Zhao1999 wants to merge 2 commits into
Conversation
… (floors, status logging, col_types, sources guard) Fixes from issue #318 robustness audit: - KMueller-Lab#2 validate version is single non-NA string before any download - KMueller-Lab#3 strip doubled 'Error:' prefixes from stop() messages - KMueller-Lab#4 iso/vars + other inputs now errors instead of silently discarding - KMueller-Lab#5 case-insensitive variable matching, normalized to canonical casing - KMueller-Lab#6 reject empty character vectors before fetching the dataset - KMueller-Lab#7 add start_year/end_year filtering across sources/raw/main paths - KMueller-Lab#1 sync bundled versions.csv to the 9 served vintages - KMueller-Lab#8 DESCRIPTION dependency floors, HTTP-status logging in .gmd_safe_get, col_types on fixed-schema CSV reads, sources-path zero-row guard Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace the superseded httr package with httr2 (issue #318, item KMueller-Lab#8): - .gmd_safe_get now uses httr2::request/req_perform with req_error() disabled so non-200 responses return NULL (with status logging) exactly as before, while genuine network failures are still caught and return NULL. - httr::content(as='raw') -> httr2::resp_body_raw() (haven::read_dta of .dta) - httr::content(as='text') -> httr2::resp_body_string(encoding='UTF-8') (read_csv) - DESCRIPTION: httr (>= 1.4.0) -> httr2 (>= 1.0.0) Behavior-preserving: all network paths and bug-fix repros verified against the live S3 backend; R CMD check Status OK. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Yicheng-Zhao1999
added a commit
to Yicheng-Zhao1999/Global-Macro-Database-R
that referenced
this pull request
Jun 29, 2026
- Trim whitespace consistently with Python/Stata; blank tokens dropped and an
empty/all-blank value becomes NULL ("no filter") instead of erroring (KMueller-Lab#4)
- Validate an invalid version before honoring cite (KMueller-Lab#7)
- Add print_option (APA citation) for parity with Python/Stata
- Add fast (local dataset cache under R_user_dir) for parity with Python/Stata
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Robustness fixes for the R
globalmacrodatapackage from the cross-language audit (#318; Stata #412, Python forthcoming). All changes were live-verified with R 4.5.3 against the live S3 backend;R CMD checkis Status: OK (0 ERROR/WARNING/NOTE).Two commits:
Bug fixes
inst/versions.csvout of sync with S32025_05,2025_08). Re-verified: all 9.dtanow return HTTP 200. Also added a clearer message when a listed version's file can't be retrieved.gmd(version=NA)→ cryptic "missing value where TRUE/FALSE needed"versionis a single non-NA character (orNULL) before any download.Error:prefix (stop()already adds one)Error:prefix from allstop()/sprintfstrings.iso=TRUE/vars=TRUE+ other args silently discarded the args (warning only)stop()s; also coverssources/cite.variablescase-sensitive whilecountry/sourcesare notrgdp→rGDP)..dtabefore failingcountry/variablesbefore fetching.start_year/end_yearfilteringapply_year_filter()helper applied across the sources/raw/main paths.Quality cleanup (#8)
Depends: R (>= 3.5.0)and version floors (readr (>= 2.0.0)is required byshow_col_types/col_types;haven (>= 2.0.0))..gmd_safe_getso 404 vs timeout are distinguishable (speculative case-insensitive source lookups stay quiet).col_typeson the fixed-schema CSV reads (versions/varlist/isomapping/source_list/bib), pinning only accessed columns so an extra S3 column is fine; the dynamic raw-variable CSV intentionally keeps inference..gmd_safe_getuseshttr2::request/req_performwithreq_error()disabled to preserve the original "non-200 → NULL" behavior;content(as="raw")→resp_body_raw(),content(as="text")→resp_body_string(encoding="UTF-8").Not done (deferred): no other #8 items remain beyond the above.
Tests
Added 7 testthat tests (5 offline validation + 2 online behavior) covering #2–#7, and retargeted the "specific version" test to a pinned older vintage now that S3 serves them.
Verification
R CMD check: Status OK (suggests forced off wheretestthatisn't installed locally)..dtaand CSV bodies; 404 status logging).🤖 Generated with Claude Code