stevecondylios / priceR

Economics and Pricing in R
https://stevecondylios.github.io/priceR/
Other
59 stars 7 forks source link

currencies() returning empty data frame #48

Open AdrianS85 opened 1 year ago

AdrianS85 commented 1 year ago

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 commented 1 year ago

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.