Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot handle missing values #56

Open
ShannonS-3791 opened this issue Nov 16, 2023 · 1 comment
Open

Cannot handle missing values #56

ShannonS-3791 opened this issue Nov 16, 2023 · 1 comment

Comments

@ShannonS-3791
Copy link

I am running the historical_exchange_rates function for multiple currencies; back to 2010. While the function works fine most of the time, I occasionally go this I get this error:

Error in pmap():
ℹ In index: 1.
Caused by error in purrr::map_dbl():
ℹ In index: 1.
ℹ With name: 2010-01-01.
Caused by error in .x[[index]]:
! subscript out of bounds
Backtrace:
1. priceR::historical_exchange_rates(...)
13. purrr::map_dbl(...)
14. purrr:::map_("double", .x, .f, ..., .progress = .progress)
18. priceR (local) .f(.x[[i]], ...)

I investigated this using the code from git, and I believe the issue occurs when running the 'get_values' function when there is no data available for a certain period. The list created via fromJSON has a line with the date, but no additional piece with the data to apply the purrr::map_dbl to.

Thank you for your attention to this matter.

@ShannonS-3791
Copy link
Author

I came up with a temporary fix on my end; and hoping my work can help. I'm not the best with apply/map, so I'm confident this (for loop) is not the most efficient code, but it gets to the root of the problem. I inserted the following code immediately after the dat <- endpoint %>% fromJSON step

dat_fix <- dat[[8]]
  
  rows_to_delete <- c()
  
  for (l in 1:length(dat_fix)) {
    if (length(dat_fix[[l]]) == 0) {
      rows_to_delete <- append(rows_to_delete,l)
    }
  }
  
  dat2 <- if(length(rows_to_delete)>0){
    dat_fix[-rows_to_delete]
  } else {dat_fix}

then in subsequent code, the dat[[8]] or response[[8]] had to be replaced with just dat2 or response

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

No branches or pull requests

1 participant