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

currencies() returning empty data frame #48

Open
AdrianS85 opened this issue Oct 11, 2023 · 1 comment
Open

currencies() returning empty data frame #48

AdrianS85 opened this issue Oct 11, 2023 · 1 comment

Comments

@AdrianS85
Copy link

AdrianS85 commented Oct 11, 2023

Dear Steve,

As in title: running priceR::currencies() returns empty data frame, while defining the same funcion within my own script works perfectly well:

currencies <- function() {

  endpoint <- "http://api.exchangerate.host/live" %>%
    priceR::append_exchangeratehost_access_key()
  
  live <- jsonlite::fromJSON(endpoint)
  
  df <- live$quotes %>%
    map_dbl(~ .x) %>%
    stack() %>%
    mutate(ind = substr(.data$ind, 4, nchar(as.character(.data$ind)))) %>%
    mutate(values = as.double(.data$values)) %>%
    .[,c(2,1)] %>%
    # Add USD since it won't be included
    add_row(ind = "USD", values = 1) %>%
    # then sort alphabetically
    arrange(.data$ind)
  
  df %>%
    select(.data$ind) %>%
    rename(code = .data$ind) %>%
    left_join(select(priceR::currency_info, .data$iso_code, .data$name), by = c("code" = "iso_code")) %>%
    select(description = .data$name, code = .data$code)
  
}
currencies()

Best,
Adrian

BTW: it also now returns 2 values for: Belarusian Ruble BYN and Belarusian Ruble BYR
BTW2: Seems to not detect some symbols (BYR was also a victim to that):

Error in priceR::historical_exchange_rates(from = currency_from, to = curr_to_exchange_to_symbol, :
Invalid currency code(s): "LTL". Run currencies()
to view all 171 valid currency codes.
@stevecondylios
Copy link
Owner

Regarding currencies() returning the empty data.frame (but seeming to work when its code is run elsewhere, e.g. in a user-defined function), the only thing I can think of is checking that the currencies() function is definitely calling the version from priceR 1.0.0 (as opposed to older versions). You can check with sessionInfo() and under 'other attached packages' it should show 'priceR_1.0.0'. If it's not that I can't think of many other things that could cause it.

Regarding Belarusian Ruble, apparently it can go by either of the 2 currency codes (at least according to wikipedia: https://en.wikipedia.org/wiki/Belarusian_ruble). The second currency code is now added.

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

2 participants