Skip to content

Examples fail with: subscript out of bounds #60

@Javdat

Description

@Javdat
> sessionInfo()
R version 4.5.0 (2025-04-11)
Platform: aarch64-apple-darwin20
Running under: macOS Sequoia 15.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_1.1.4  priceR_1.0.2

loaded via a namespace (and not attached):
 [1] tidyr_1.3.1       R6_2.6.1          lubridate_1.9.4   tidyselect_1.2.1  magrittr_2.0.3    glue_1.8.0        stringr_1.5.1    
 [8] tibble_3.3.0      pkgconfig_2.0.3   timechange_0.3.0  generics_0.1.4    lifecycle_1.0.4   cli_3.6.5         proto_1.0.0      
[15] vctrs_0.6.5       compiler_4.5.0    purrr_1.0.4       rstudioapi_0.17.1 tools_4.5.0       pillar_1.10.2     gsubfn_0.7       
[22] jsonlite_2.0.0    rlang_1.1.6       stringi_1.8.7    

Examples fail with both CRAN and GitHub version.

Example below is with priceR_1.0.2 in R 4.5.0.

> library(priceR)
> library(dplyr)
Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union
> 
> sales_transactions <- tibble(
+     local_price = c(100, 80, 9200, 90),
+     local_currency = c("USD", "EUR", "JPY", "USD"),
+     final_currency = c("EUR", "USD", "USD", "JPY"),
+     date_transaction = lubridate::ymd(c(20200601, 20200609, 20200614, 20200623))
+ )
> # Some made-up sales transactions of different values and currencies
> sales_transactions %>%
+     mutate(
+         converted_price = convert_currencies(
+             price_start = local_price,
+             from = local_currency,
+             to = final_currency,
+             date = date_transaction
+         )
+     )
For full currency exchange rate API documentation visit:
 https://exchangerate.host/#/#docs
 (this message will only appear once per session)
Error in `mutate()`:
ℹ In argument: `converted_price = convert_currencies(...)`.
ℹ In group 2: `from_to = "JPY.USD"`.
Caused by error in `dplyr::summarise()`:
ℹ In argument: `rates_lookup = purrr::pmap(.l = list(from, to, date_range), .f =
  from_to_dates_rates)`.
ℹ In group 2: `from_to = "JPY.USD"`.
Caused by error in `purrr::pmap()`:
ℹ In index: 1.
Caused by error in `pmap()`:
ℹ In index: 1.
Caused by error in `dat[[8]]`:
! subscript out of bounds
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/dplyr:::mutate_error>
Error in `mutate()`:
ℹ In argument: `converted_price = convert_currencies(...)`.
ℹ In group 2: `from_to = "JPY.USD"`.
Caused by error in `dplyr::summarise()`:
ℹ In argument: `rates_lookup = purrr::pmap(.l = list(from, to, date_range), .f = from_to_dates_rates)`.
ℹ In group 2: `from_to = "JPY.USD"`.
Caused by error in `purrr::pmap()`:
ℹ In index: 1.
---
Backtrace:
     ▆
  1. ├─sales_transactions %>% ...
  2. ├─dplyr::mutate(...)
  3. ├─dplyr:::mutate.data.frame(...)
  4. │ └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
  5. │   ├─base::withCallingHandlers(...)
  6. │   └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
  7. │     └─mask$eval_all_mutate(quo)
  8. │       └─dplyr (local) eval()
  9. ├─priceR::convert_currencies(...)
 10. │ └─... %>% tidyr::unnest(rates_lookup)
 11. ├─tidyr::unnest(., rates_lookup)
 12. ├─dplyr::select(., -date_range)
 13. ├─dplyr::summarise(...)
 14. ├─dplyr:::summarise.grouped_df(...)
 15. │ └─dplyr:::summarise_cols(.data, dplyr_quosures(...), by, "summarise")
 16. │   ├─base::withCallingHandlers(...)
 17. │   └─dplyr:::map(quosures, summarise_eval_one, mask = mask)
 18. │     └─base::lapply(.x, .f, ...)
 19. │       └─dplyr (local) FUN(X[[i]], ...)
 20. │         └─mask$eval_all_summarise(quo)
 21. │           └─dplyr (local) eval()
 22. ├─purrr::pmap(.l = list(from, to, date_range), .f = from_to_dates_rates)
 23. │ └─purrr:::pmap_("list", .l, .f, ..., .progress = .progress)
 24. │   ├─purrr:::with_indexed_errors(...)
 25. │   │ └─base::withCallingHandlers(...)
 26. │   ├─purrr:::call_with_cleanup(...)
 27. │   └─priceR (local) .f(.l[[1L]][[i]], .l[[2L]][[i]], .l[[3L]][[i]], ...)
 28. │     ├─... %>% purrr::set_names("date", "rate")
 29. │     └─priceR::historical_exchange_rates(...)
 30. │       └─purrr::pmap_dfr(...)
 31. │         └─purrr::pmap(.l, .f, ...)
 32. │           └─purrr:::pmap_("list", .l, .f, ..., .progress = .progress)
 33. │             ├─purrr:::with_indexed_errors(...)
 34. │             │ └─base::withCallingHandlers(...)
 35. │             ├─purrr:::call_with_cleanup(...)
 36. │             └─priceR (local) .f(start_date = .l[[1L]][[i]], end_date = .l[[2L]][[i]], ...)
 37. │               └─dat[[8]] %>% length
 38. ├─purrr::set_names(., "date", "rate")
 39. ├─purrr (local) `<fn>`(`<sbscOOBE>`)
 40. │ └─cli::cli_abort(...)
 41. │   └─rlang::abort(...)
 42. │     └─rlang:::signal_abort(cnd, .file)
 43. │       └─base::signalCondition(cnd)
 44. └─purrr (local) `<fn>`(`<prrr_rr_>`)
 45.   └─cli::cli_abort(...)
---
Caused by error in `pmap()`:
ℹ In index: 1.
Caused by error in `dat[[8]]`:
! subscript out of bounds
---
Backtrace:
     ▆
  1. ├─sales_transactions %>% ...
  2. ├─dplyr::mutate(...)
  3. ├─dplyr:::mutate.data.frame(...)
  4. │ └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
  5. │   ├─base::withCallingHandlers(...)
  6. │   └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
  7. │     └─mask$eval_all_mutate(quo)
  8. │       └─dplyr (local) eval()
  9. ├─priceR::convert_currencies(...)
 10. │ └─... %>% tidyr::unnest(rates_lookup)
 11. ├─tidyr::unnest(., rates_lookup)
 12. ├─dplyr::select(., -date_range)
 13. ├─dplyr::summarise(...)
 14. ├─dplyr:::summarise.grouped_df(...)
 15. │ └─dplyr:::summarise_cols(.data, dplyr_quosures(...), by, "summarise")
 16. │   ├─base::withCallingHandlers(...)
 17. │   └─dplyr:::map(quosures, summarise_eval_one, mask = mask)
 18. │     └─base::lapply(.x, .f, ...)
 19. │       └─dplyr (local) FUN(X[[i]], ...)
 20. │         └─mask$eval_all_summarise(quo)
 21. │           └─dplyr (local) eval()
 22. ├─purrr::pmap(.l = list(from, to, date_range), .f = from_to_dates_rates)
 23. │ └─purrr:::pmap_("list", .l, .f, ..., .progress = .progress)
 24. │   ├─purrr:::with_indexed_errors(...)
 25. │   │ └─base::withCallingHandlers(...)
 26. │   ├─purrr:::call_with_cleanup(...)
 27. │   └─priceR (local) .f(.l[[1L]][[i]], .l[[2L]][[i]], .l[[3L]][[i]], ...)
 28. │     ├─... %>% purrr::set_names("date", "rate")
 29. │     └─priceR::historical_exchange_rates(...)
 30. │       └─purrr::pmap_dfr(...)
 31. │         └─purrr::pmap(.l, .f, ...)
 32. │           └─purrr:::pmap_("list", .l, .f, ..., .progress = .progress)
 33. │             ├─purrr:::with_indexed_errors(...)
 34. │             │ └─base::withCallingHandlers(...)
 35. │             ├─purrr:::call_with_cleanup(...)
 36. │             └─priceR (local) .f(start_date = .l[[1L]][[i]], end_date = .l[[2L]][[i]], ...)
 37. │               └─dat[[8]] %>% length
 38. └─purrr::set_names(., "date", "rate")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions