View source: R/get_normative_txt.R
| get_normative_txt | R Documentation |
For each row of the input data.frame, constructs the appropriate URL for the Bacen normatives API, performs the request, extracts the returned content and applies basic cleaning to the text fields (Assunto and Texto). Returns a data.frame with all aggregated contents.
get_normative_txt(normative_data)
normative_data |
data.frame. A data.frame with at least the columns:
|
The function performs the following steps:
Iterates over each row of normative_data (prints the iteration index for monitoring).
Encodes the normative type for URL usage (using URLencode(..., reserved = TRUE)).
Chooses the API route depending on the type:
for "Comunicado", "Ato de Diretor" and "Ato do Presidente" it uses the other-norms endpoint (exibeoutrasnormas);
for the rest, it uses the standard normative endpoint (exibenormativo).
Makes the HTTP request (via httr::GET) and converts the returned JSON into a data.frame.
Extracts and cleans textual fields:
converts HTML to plain text for the fields Assunto and Texto (using xml2::read_html + xml2::xml_text),
removes line breaks and extra spaces (stringr::str_replace_all, stringr::str_squish).
Aggregates each result into a final data.frame returned by the function.
data.frame with the records returned by the API for each reference in normative_data,
including the extracted and post-processed fields (e.g., Assunto, Texto).
The function assumes the BCB API returns a conteudo field with the expected fields.
Request errors or changes in the API structure may cause failures; consider handling exceptions around the call if needed.
Packages used internally: httr, jsonlite, xml2, stringr, dplyr, glue, purrr.
# First, download normative data
normative_data <- get_normative_data(
"Cooperativa",
"2023-08-01",
"2023-08-10")
# Then, download the full texts for the retrieved normatives
normative_txt <- get_normative_txt(normative_data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.