| Title: | Access 'BCRPDATA' API |
|---|---|
| Description: | Search and access more than ten thousand datasets included in 'BCRPDATA' (see <https://estadisticas.bcrp.gob.pe/estadisticas/series/ayuda/bcrpdata> for more information). |
| Authors: | Julio Collazos [aut, cre] (ORCID: <https://orcid.org/0009-0006-5503-0997>) |
| Maintainer: | Julio Collazos <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.2 |
| Built: | 2026-05-22 08:07:58 UTC |
| Source: | https://github.com/juliocollazos64/bcrp |
Perform an API request to BCRPData
get_bcrp_data( codes, from = NA, to = NA, request_strategy = c("sequential", "parallel") )get_bcrp_data( codes, from = NA, to = NA, request_strategy = c("sequential", "parallel") )
codes |
A character vector with valid BCRPData series codes, see the |
from |
A character vector of length 1, usually a year see Details. Optional. |
to |
A character vector of length 1. Must be greater than the
|
request_strategy |
Either "sequential" (default) or "parallel". This defines the strategy to be followed when making requests for more than one code. Visit httr2 for more details. |
It is possible to specify only the from or to arguments in which case the request to the BCRPData API would only take into consideration the non-missing argument, if both are ommited the API will respond with the latest data.
BCRPData has data of different frequencies, it's important to consider that when defining the from and to arguments. Here's a list you can use to define the most suitable values to the from and to arguments.
Yearly: Provide a year, e.g 2018
Quarterly: Provide a year followed by a hyphen followed by the quarter in its numerical value, e.g 2018-2
Monthly: Provide a year followed by a hyphen followed by the month in its numerical value, e.g 2018-5
Daily: Provide a year followed by a hyphen followed by the month and followed by the day, e.g 2018-5-5
This function will try to get all the valid codes you provided in its codes argument, if one of the requests fails it will stop its execution for all the codes and return an error, pointing out which codes caused this.
Data frame with code-level observations.
Julio Collazos.
codes <- c("PN00009MM", "PN00002MM", "PN01270PM", "PD39557DA") # Will get you the most recent data for these codes # as you have not provided the `from` and `to` arguments. get_bcrp_data(codes = codes) # You can also provide the range of dates # through the `from` and `to` arguments. get_bcrp_data(codes = codes, from = "2015-01", to = "2020-01") # If needed, you can sometimes speed up your data API calls # by performing them in parallel. In this example we are # querying just 5 codes so the benefits of parallelism does not # outweigh its cost, making the request slower. ## Not run: get_bcrp_data(codes = codes, request_strategy = "parallel") ## End(Not run)codes <- c("PN00009MM", "PN00002MM", "PN01270PM", "PD39557DA") # Will get you the most recent data for these codes # as you have not provided the `from` and `to` arguments. get_bcrp_data(codes = codes) # You can also provide the range of dates # through the `from` and `to` arguments. get_bcrp_data(codes = codes, from = "2015-01", to = "2020-01") # If needed, you can sometimes speed up your data API calls # by performing them in parallel. In this example we are # querying just 5 codes so the benefits of parallelism does not # outweigh its cost, making the request slower. ## Not run: get_bcrp_data(codes = codes, request_strategy = "parallel") ## End(Not run)
Access metadata for all available datasets provided by the Peruvian Central Bank
get_bcrp_metadata()get_bcrp_metadata()
A data frame with one row per code available for request.
Julio Collazos
# No arguments required, simply call the function. get_bcrp_metadata()# No arguments required, simply call the function. get_bcrp_metadata()