Skip to content

20260616/#413 double check errors in r#8

Open
Yicheng-Zhao1999 wants to merge 2 commits into
KMueller-Lab:mainfrom
Yicheng-Zhao1999:20260616/#413-double-check-errors-in-R
Open

20260616/#413 double check errors in r#8
Yicheng-Zhao1999 wants to merge 2 commits into
KMueller-Lab:mainfrom
Yicheng-Zhao1999:20260616/#413-double-check-errors-in-R

Conversation

@Yicheng-Zhao1999

@Yicheng-Zhao1999 Yicheng-Zhao1999 commented Jun 19, 2026

Copy link
Copy Markdown

Summary

Robustness fixes for the R globalmacrodata package, from the cross-language audit in #318. Every change was live-verified with R 4.5.3 against the live S3 backend (download paths, bug repros, and a full regression after each change).

Two audit items are intentionally not changed here:

  • Listed versions returning 404 (Shixuan #1): root cause is server-side data, not R code. Re-verified that all advertised vintages now return data on S3, so no code change is warranted.
  • Doubled Error: prefix (Update NAMESPACE #3): could not be reproduced; left as-is.

Bug fixes

# Problem Fix
2 gmd(version = NA) crashed with a cryptic missing value where TRUE/FALSE needed Validate version is a single non-NA character string (or NULL) at the top of gmd(), before any download
4 gmd(iso = TRUE, country = "USA") only warned, then silently discarded the extra args Now errors (stop) on conflicting inputs; the guard also covers sources/cite
5 variables was case-sensitive while country/sources were not (variables = "rgdp" failed) Case-insensitive matching, normalized to the canonical casing (e.g. rgdprGDP); invalid codes still error
6 Empty character vectors (country = character(0), …) downloaded the full ~21 MB dataset before failing Reject empty country/variables (and empty/NA cite) up front, before any network request
7 start_year / end_year were not implemented (unused argument) Added both parameters plus an apply_year_filter() helper applied across the main, raw, and sources paths; validated up front

Quality / robustness improvements (audit item #8)

  • Dependencies: added Depends: R (>= 3.5.0) and version floors (readr (>= 2.0.0), httr2 (>= 1.0.0), haven (>= 2.0.0)); migrated from the superseded httr to httr2 (request/req_perform/resp_body_*, with req_error() disabled to preserve the non-200 → NULL behaviour).
  • CSV parsing: replaced type guessing with explicit col_types on the fixed-schema CSVs (versions, varlist, isomapping, source_list, bib) and the stable id columns of the raw CSV (ISO3/countryname/year); dynamic source columns remain inferred.
  • Diagnostics: .gmd_safe_get now logs the HTTP status code (or the error message) on failure, so users can distinguish a 404 from a timeout. Still returns NULL, so control flow is unchanged.
  • Return type: all data-returning paths now return a plain data.frame (previously a mix of tbl_df / spec_tbl_df / data.frame); the vars list keeps its custom gmd_vars print class.

Testing

  • Verified against the live S3 backend: all 8 download paths (text CSV + binary .dta), each bug's before/after repro, and a 13-point regression re-run after every change.
  • start_year/end_year year windows, case-insensitive variable/source names, and the empty-vector/NA guards all behave as expected; existing happy-path calls are unchanged.

🤖 Generated with Claude Code

@Yicheng-Zhao1999
Yicheng-Zhao1999 force-pushed the 20260616/#413-double-check-errors-in-R branch from 79ff9d0 to e9e7334 Compare June 29, 2026 15:06
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.

1 participant