Title: | Wrapper for the National Bank of Poland API |
Version: | 0.2.2 |
Maintainer: | Ryszard Szymanski <ryszard.szymanski@outlook.com> |
Description: | Use the https://api.nbp.pl/ API through R. Retrieve currency exchange rates and gold prices data published by the National Bank of Poland in form of convenient R objects. |
License: | GPL-3 |
BugReports: | https://github.com/szymanskir/rnbp/issues |
Encoding: | UTF-8 |
Imports: | curl, httr, jsonlite, utils |
Suggests: | covr, httptest, testthat (≥ 2.1.0), knitr, rmarkdown, ggplot2 |
RoxygenNote: | 7.3.2 |
VignetteBuilder: | knitr |
URL: | https://github.com/szymanskir/rnbp |
NeedsCompilation: | no |
Packaged: | 2025-03-23 20:28:56 UTC; Rysza |
Author: | Ryszard Szymanski [aut, cre] |
Repository: | CRAN |
Date/Publication: | 2025-03-23 20:40:02 UTC |
Returns the base url for the gold price endpoint.
Description
Returns the base url for the gold price endpoint.
Usage
.goldprice_base_url()
Returns the base url for the rates endpoint.
Description
Returns the base url for the rates endpoint.
Usage
.rates_base_url()
Sends a request and parses the gold price endpoint response.
Description
Sends a request and parses the gold price endpoint response.
Usage
.send_gold_endpoint_request(request_url)
Arguments
request_url |
url to which the request should be sent. |
Value
nbp_api_response object with the request content.
Sends a request and parses the rates endpoint response.
Description
Sends a request and parses the rates endpoint response.
Usage
.send_rates_endpoint_request(request_url)
Arguments
request_url |
url to which the request should be sent. |
Value
nbp_api_response object with the request content.
Sends a request and parses the tables endpoint response.
Description
Sends a request and parses the tables endpoint response.
Usage
.send_tables_endpoint_request(request_url)
Arguments
request_url |
url to which the request should be sent. |
Value
nbp_api_response object with the request content.
Returns the base url for the tables endpoint.
Description
Returns the base url for the tables endpoint.
Usage
.tables_base_url()
Adds the json formatting option to the passed url request.
Description
Adds the json formatting option to the passed url request.
Usage
add_json_format(url)
Arguments
url |
request url to which the json format option should be added |
Value
url with json format option added
Adds a path part to the given url
Description
Adds a path part to the given url
Usage
add_path_part(url, path_name)
Arguments
url |
url to which a path part should be added |
path_name |
path part which should be added to the url |
Value
url with the path part added
Creates a request with the given path parts. The json format argument is included by default.
Description
Creates a request with the given path parts. The json format argument is included by default.
Usage
create_request(base_url, path_parts = NULL)
Arguments
base_url |
base url of the API for which a request should be created |
path_parts |
that should be added to the base url |
Value
request url composed of the given base url and specified path parts
Retrieves the current exchange rate for the given currency.
Description
Retrieves the current exchange rate for the given currency.
Usage
get_current_exchangerate(table, currency_code)
Arguments
table |
specifies which from which table the exchange rate should be fetched. |
currency_code |
code of the currency for which the exchange rate should be fetched. |
Value
nbp_api_response object containing the current exchange rate.
See Also
https://api.nbp.pl/#kursyWalut
Other rates:
get_exchangerate_from()
,
get_exchangerate_from_interval()
,
get_last_n_exchangerates()
,
get_todays_exchangerate()
Examples
tryCatch(
{
## Retrieve the current exchange rate for euros
response <- get_current_exchangerate("A", "EUR")
## Retrieve the content
response$content
},
error = function(e) message(e)
)
Retrieves the current exchange rate table.
Description
Retrieves the current exchange rate table.
Usage
get_current_exchangerate_table(table)
Arguments
table |
specifies which table should be fetched. |
Value
nbp_api_response object containing the current exchange rate table.
See Also
https://api.nbp.pl/#kursyWalut
Other tables:
get_exchangerate_table_from()
,
get_exchangerate_tables_from_interval()
,
get_last_n_exchangerate_tables()
,
get_todays_exchangerate_table()
Examples
tryCatch(
{
## Retrieve the current A exchange rate table
response <- get_current_exchangerate_table("A")
## Retrieve the content
response$content
},
error = function(e) message(e)
)
Retrieves the current gold price.
Description
Retrieves the current gold price.
Usage
get_current_goldprice()
Value
nbp_api_response object containing the current gold price.
See Also
Other goldprice:
get_goldprice_from()
,
get_goldprice_from_interval()
,
get_last_n_goldprices()
,
get_todays_goldprice()
Examples
tryCatch(
{
## Fetch the current gold price
response <- get_current_goldprice()
## Retrieve the current gold price value
response$content$cena
},
error = function(e) message(e)
)
Retrieves the exchange rate from a specific date.
Description
Retrieves the exchange rate from a specific date.
Usage
get_exchangerate_from(table, currency_code, date)
Arguments
table |
specifies which from which table the exchange rate should be fetched. |
currency_code |
code of the currency for which the exchange rate should be fetched. |
date |
date from which the exchange rate should be fetched. |
Details
As exchange rates are not published on the weekends fetching values from a weekend date will result in a 404 error. In those cases the function returns an error with an appropriate message.
Value
nbp_api_response object containing the exchange rate from the specified date.
See Also
https://api.nbp.pl/#kursyWalut
Other rates:
get_current_exchangerate()
,
get_exchangerate_from_interval()
,
get_last_n_exchangerates()
,
get_todays_exchangerate()
Examples
tryCatch(
{
## Fetch the euro exchange rate from a week ago
response <- get_exchangerate_from("A", "EUR", Sys.Date() - 7)
## Preview response content
response$content
},
error = function(e) message(e)
)
Retrieves the exchange rates from a specific interval.
Description
Retrieves the exchange rates from a specific interval.
Usage
get_exchangerate_from_interval(table, currency_code, from, to)
Arguments
table |
specifies which from which table the exchange rate should be fetched. |
currency_code |
code of the currency for which the exchange rate should be fetched. |
from |
start day of the interval. |
to |
end day of the interval. |
Details
As exchange rates are not published on the weekends fetching values from an interval containing a weekend will result in a response that omits those days.
Value
nbp_api_response object containing the exchange rates from the specified interval.
See Also
https://api.nbp.pl/#kursyWalut
Other rates:
get_current_exchangerate()
,
get_exchangerate_from()
,
get_last_n_exchangerates()
,
get_todays_exchangerate()
Examples
tryCatch(
{
## Fetch the exchange rate table from the past week
response <- get_exchangerate_tables_from_interval("A", Sys.Date() - 7, Sys.Date())
## Preview response content
response$content
},
error = function(e) message(e)
)
Retrieves the exchange rate table from a specific date.
Description
Retrieves the exchange rate table from a specific date.
Usage
get_exchangerate_table_from(table, date)
Arguments
table |
specifies which table should be fetched. |
date |
date from which the exchange rate table should be fetched. |
Details
As exchange rate tables are not published on the weekends fetching values from a weekend date will result in a 404 error. In those cases the function returns an error with an appropriate message.
Value
nbp_api_response object containing the exchange rate table from the specified date.
See Also
https://api.nbp.pl/#kursyWalut
Other tables:
get_current_exchangerate_table()
,
get_exchangerate_tables_from_interval()
,
get_last_n_exchangerate_tables()
,
get_todays_exchangerate_table()
Examples
tryCatch(
{
## Fetch the A exchange rate table from a week ago
response <- get_exchangerate_table_from("A", Sys.Date() - 7)
## Preview response content
response$content
},
error = function(e) message(e)
)
Retrieves the exchange rate tables from a specific interval.
Description
Retrieves the exchange rate tables from a specific interval.
Usage
get_exchangerate_tables_from_interval(table, from, to)
Arguments
table |
specifies which table should be fetched. |
from |
start day of the interval. |
to |
end day of the interval. |
Details
As exchange rate tables are not published on the weekends fetching values from an interval containing a weekend will result in a response that omits those days.
Value
nbp_api_response object containing the exchange rates tables from the specified interval.
See Also
https://api.nbp.pl/#kursyWalut
Other tables:
get_current_exchangerate_table()
,
get_exchangerate_table_from()
,
get_last_n_exchangerate_tables()
,
get_todays_exchangerate_table()
Examples
tryCatch(
{
## Fetch the exchange rate table from the past week
response <- get_exchangerate_tables_from_interval("A", Sys.Date() - 7, Sys.Date())
## Preview response content
response$content
},
error = function(e) message(e)
)
Retrieves the gold price from a specific date.
Description
Retrieves the gold price from a specific date.
Usage
get_goldprice_from(date)
Arguments
date |
date from which the gold price should be fetched. |
Details
As gold prices are not published on the weekends fetching values from a weekend date will result in a 404 error. In those cases the function returns an error with an appropriate message.
Value
nbp_api_response object containing the gold price from the specified date.
See Also
Other goldprice:
get_current_goldprice()
,
get_goldprice_from_interval()
,
get_last_n_goldprices()
,
get_todays_goldprice()
Examples
tryCatch(
{
## Fetch the gold price from a week ago
response <- get_goldprice_from(Sys.Date() - 7)
## Preview response content
response$content
},
error = function(e) message(e)
)
Retrieves the gold prices from a specific interval.
Description
Retrieves the gold prices from a specific interval.
Usage
get_goldprice_from_interval(from, to)
Arguments
from |
start day of the interval. |
to |
end day of the interval. |
Details
As gold prices are not published on the weekends fetching values from an interval containing a weekend will result in a response that omits those days.
Value
nbp_api_response object containing the gold prices from the specified interval.
See Also
Other goldprice:
get_current_goldprice()
,
get_goldprice_from()
,
get_last_n_goldprices()
,
get_todays_goldprice()
Examples
tryCatch(
{
## Fetch the gold prices from the past week
response <- get_goldprice_from_interval(Sys.Date() - 7, Sys.Date())
## Preview response content
response$content
},
error = function(e) message(e)
)
Retrieves the last n exchange rate tables.
Description
Retrieves the last n exchange rate tables.
Usage
get_last_n_exchangerate_tables(table, n)
Arguments
table |
specifies which table should be fetched. |
n |
number of exchange rate tables to retrieve. |
Value
nbp_api_response object containing the last n exchange rate tables.
See Also
https://api.nbp.pl/#kursyWalut
Other tables:
get_current_exchangerate_table()
,
get_exchangerate_table_from()
,
get_exchangerate_tables_from_interval()
,
get_todays_exchangerate_table()
Examples
tryCatch(
{
## Fetch the last 3 A exchange rate tables
response <- get_last_n_exchangerate_tables("A", 3)
## Preview response content
response$content
},
error = function(e) message(e)
)
Retrieves the last n exchange rates.
Description
Retrieves the last n exchange rates.
Usage
get_last_n_exchangerates(table, currency_code, n)
Arguments
table |
specifies which from which table the exchange rate should be fetched. |
currency_code |
code of the currency for which the exchange rate should be fetched. |
n |
number of exchange rates to retrieve. |
Value
nbp_api_response object containing the last n exchange rates.
See Also
https://api.nbp.pl/#kursyWalut
Other rates:
get_current_exchangerate()
,
get_exchangerate_from()
,
get_exchangerate_from_interval()
,
get_todays_exchangerate()
Examples
tryCatch(
{
## Fetch the last 3 exhange rates for euros
response <- get_last_n_exchangerates("A", "EUR", 3)
## Preview response content
response$content
},
error = function(e) message(e)
)
Retrieves the last n gold prices.
Description
Retrieves the last n gold prices.
Usage
get_last_n_goldprices(n)
Arguments
n |
number of gold prices to retrieve. |
Value
nbp_api_response object containing the last n gold prices.
See Also
Other goldprice:
get_current_goldprice()
,
get_goldprice_from()
,
get_goldprice_from_interval()
,
get_todays_goldprice()
Examples
tryCatch(
{
## Fetch the last 3 gold price values
response <- get_last_n_goldprices(3)
## Preview response content
response$content
},
error = function(e) message(e)
)
Retrieves the exchange rate that was published today.
Description
Retrieves the exchange rate that was published today.
Usage
get_todays_exchangerate(table, currency_code)
Arguments
table |
specifies which from which table the exchange rate should be fetched. |
currency_code |
code of the currency for which the exchange rate should be fetched. |
Details
If today's data is not available the API will return a 404 Not found error. In that case the function will return an error with an appropriate message.
Value
nbp_api_response object containing today's exchange rate.
See Also
https://api.nbp.pl/#kursyWalut
Other rates:
get_current_exchangerate()
,
get_exchangerate_from()
,
get_exchangerate_from_interval()
,
get_last_n_exchangerates()
Examples
tryCatch(
{
## Fetch todays A exchange rate table
response <- get_todays_exchangerate("A", "EUR")
## Preview response content
response$content
},
error = function(e) message(e)
)
Retrieves the exchange rate table that was published today.
Description
Retrieves the exchange rate table that was published today.
Usage
get_todays_exchangerate_table(table)
Arguments
table |
specifies which table should be fetched. |
Details
If today's data is not available the API will return a 404 Not found error. In that case the function will return an error with an appropriate message.
Value
nbp_api_response object containing today's exchange rate table.
See Also
https://api.nbp.pl/#kursyWalut
Other tables:
get_current_exchangerate_table()
,
get_exchangerate_table_from()
,
get_exchangerate_tables_from_interval()
,
get_last_n_exchangerate_tables()
Examples
tryCatch(
{
## Fetch todays A exchange rate table
response <- get_todays_exchangerate_table("A")
## Preview response content
response$content
},
error = function(e) message(e)
)
Retrieves the gold price that was published today.
Description
Retrieves the gold price that was published today.
Usage
get_todays_goldprice()
Details
If today's data is not available the API will return a 404 Not found error. In that case the function will return an error with an appropriate message.
Value
nbp_api_response object containing today's gold price.
See Also
Other goldprice:
get_current_goldprice()
,
get_goldprice_from()
,
get_goldprice_from_interval()
,
get_last_n_goldprices()
Examples
tryCatch(
{
## Fetch todays gold price
response <- get_todays_goldprice()
## Preview response content
response$content
},
error = function(e) message(e)
)
Checks if an object is a positive integer.
Description
Checks if an object is a positive integer.
Usage
is_count(x)
Arguments
x |
object to be tested. |
Value
TRUE or FALSE depending on whether its argument is a positive integer or not.
Checks if an object is a date object.
Description
Checks if an object is a date object.
Usage
is_date(x)
Arguments
x |
object to be tested. |
Value
TRUE or FALSE depending on whether its arguments is a date object or not.
Checks if an object is an integer.
Description
Checks if an object is an integer.
Usage
is_integer(x)
Arguments
x |
object to be tested. |
Value
TRUE or FALSE depending on whether its argument is an integer or not.
Checks whether the given object is of the class nbp_api_response.
Description
Checks whether the given object is of the class nbp_api_response.
Usage
is_nbp_api_response(x)
Arguments
x |
object to test if it is of the class nbp_api_response |
Value
TRUE if the object is of the class nbp_api_response
Returns the base url of the nbp api.
Description
Returns the base url of the nbp api.
Usage
nbp_api_base_url()