Skip to content

Fix API response parsing in retrieve_historical_rates function#61

Open
Javdat wants to merge 1 commit intostevecondylios:masterfrom
Javdat:master
Open

Fix API response parsing in retrieve_historical_rates function#61
Javdat wants to merge 1 commit intostevecondylios:masterfrom
Javdat:master

Conversation

@Javdat
Copy link

@Javdat Javdat commented Jul 2, 2025

This commit fixes #60 where convert_currencies() was failing with "subscript out of bounds" error when accessing dat[[8]] in the retrieve_historical_rates function.

Changes:

  • Replace hard-coded dat[[8]] references with dat$quotes for accessing exchange rate data
  • Update currency pair extraction to handle new API format (e.g., "USDJPY" instead of indexed fields)
  • Add proper error handling for API failures with informative error messages
  • Use named field access throughout to make code resilient to future API changes

The exchangerate.host API response structure has changed from using numeric indices to named fields. This update ensures the package works with the current API format while being more maintainable for future
changes.

Fixes the error reported when running:

convert_currencies(
  price_start = c(100, 80, 9200, 90),
  from = c("USD", "EUR", "JPY", "USD"),
  to = c("EUR", "USD", "USD", "JPY"),
  date = lubridate::ymd(c(20200601, 20200609, 20200614, 20200623))
)

Tested with R 4.5.0 and priceR 1.0.2.

Update retrieve_historical_rates to handle changed exchangerate.host API response structure. Replace hard-coded numeric index access with named field access to prevent "subscript out of bounds" errors.
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.

Examples fail with: subscript out of bounds

1 participant