Learn R Programming

rnbp

The rnbp package is an R wrapper for the National Bank of Poland API: https://api.nbp.pl/

Installation

The rnbp package is available on CRAN, you can install it with:

install.packages("rnbp")

You can install the the development version of rnbp from GitHub with:

# install.packages("devtools")
devtools::install_github("szymanskir/rnbp")

Retrieve the currently effective exchange rate table

library(rnbp)
library(ggplot2)

## Retrieve current C exchange rate table
response <- get_current_exchangerate_table("C")

## Retrieve content from the response
current_exchangerate_table <- response$content$rates[[1]]

ggplot(current_exchangerate_table, aes(x = code, y = bid, fill = code)) +
  geom_bar(stat = "identity")

Retrieve exchange rates for specific currencies

## Retrieve last 20 exchange rates for euros
euros_response <- get_last_n_exchangerates("A", "EUR", 20)

## Retrieve last 20 exchange rates for euros
dollars_response <- get_last_n_exchangerates("A", "USD", 20)

## Retrieve rates data
euros_data <- euros_response$content$rates
dollars_data <- dollars_response$content$rates

## Add currency code columns
euros_data$code <- euros_response$content$code
dollars_data$code <- dollars_response$content$code
currency_data <- rbind(euros_data, dollars_data)

ggplot(currency_data, aes(x = effectiveDate, y = mid, col = code)) +
  geom_line() +
  geom_point()

Retrieve gold prices

current_date <- Sys.Date()
response <- get_goldprice_from_interval(current_date - 90, current_date)

ggplot(response$content, aes(x = data, y = cena)) +
  geom_point() +
  geom_line() +
  geom_smooth(method = "loess", formula = y ~ x)

Copy Link

Version

Install

install.packages('rnbp')

Monthly Downloads

239

Version

0.2.2

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Ryszard Szymanski

Last Published

March 23rd, 2025

Functions in rnbp (0.2.2)

get_exchangerate_tables_from_interval

Retrieves the exchange rate tables from a specific interval.
get_last_n_exchangerates

Retrieves the last n exchange rates.
get_goldprice_from

Retrieves the gold price from a specific date.
is_integer

Checks if an object is an integer.
get_goldprice_from_interval

Retrieves the gold prices from a specific interval.
is_count

Checks if an object is a positive integer.
get_current_exchangerate_table

Retrieves the current exchange rate table.
get_current_goldprice

Retrieves the current gold price.
get_todays_exchangerate_table

Retrieves the exchange rate table that was published today.
get_todays_goldprice

Retrieves the gold price that was published today.
get_last_n_goldprices

Retrieves the last n gold prices.
get_todays_exchangerate

Retrieves the exchange rate that was published today.
nbp_api_base_url

Returns the base url of the nbp api.
is_date

Checks if an object is a date object.
is_nbp_api_response

Checks whether the given object is of the class nbp_api_response.
.send_rates_endpoint_request

Sends a request and parses the rates endpoint response.
add_path_part

Adds a path part to the given url
create_request

Creates a request with the given path parts. The json format argument is included by default.
.rates_base_url

Returns the base url for the rates endpoint.
get_current_exchangerate

Retrieves the current exchange rate for the given currency.
.send_gold_endpoint_request

Sends a request and parses the gold price endpoint response.
.tables_base_url

Returns the base url for the tables endpoint.
.send_tables_endpoint_request

Sends a request and parses the tables endpoint response.
.goldprice_base_url

Returns the base url for the gold price endpoint.
add_json_format

Adds the json formatting option to the passed url request.
get_exchangerate_table_from

Retrieves the exchange rate table from a specific date.
get_last_n_exchangerate_tables

Retrieves the last n exchange rate tables.
get_exchangerate_from

Retrieves the exchange rate from a specific date.
get_exchangerate_from_interval

Retrieves the exchange rates from a specific interval.