Type: | Package |
Title: | Access Brazilian Economic, Demographic, Environmental, and Geopolitical Data via RESTful APIs and Curated Datasets |
Version: | 0.1.0 |
Maintainer: | Renzo Caceres Rossi <arenzocaceresrossi@gmail.com> |
Description: | Provides functions to access data from the 'BrasilAPI' and the 'REST Countries API', related to Brazil's postal codes, banks, holidays, company registrations, and international country indicators. Additionally, the package includes curated datasets related to Brazil, covering topics such as demographic data (males and females by state and year), river levels, environmental emission factors, film festivals, and yellow fever outbreak records. The package supports research and analysis focused on Brazil by integrating open APIs with high-quality datasets from multiple domains. For more details on the 'BrasilAPI', see https://brasilapi.com.br/, and for 'REST Countries', see https://restcountries.com/. |
License: | GPL-3 |
URL: | https://github.com/lightbluetitan/brazildataapi, https://lightbluetitan.github.io/brazildataapi/ |
BugReports: | https://github.com/lightbluetitan/brazildataapi/issues |
Encoding: | UTF-8 |
LazyData: | true |
Depends: | R (≥ 4.1.0) |
Imports: | utils, httr, jsonlite, dplyr |
Suggests: | ggplot2, testthat (≥ 3.0.0), knitr, rmarkdown |
RoxygenNote: | 7.3.2 |
Config/testthat/edition: | 3 |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2025-07-06 21:32:23 UTC; renzorossiv |
Author: | Renzo Caceres Rossi
|
Repository: | CRAN |
Date/Publication: | 2025-07-09 13:40:09 UTC |
BrazilDataAPI: Access Brazilian Economic, Demographic, Environmental, and Geopolitical Data via RESTful APIs and Curated Datasets
Description
This package provides functions to access data from the 'BrasilAPI' and the 'REST Countries API',related to Brazil's postal codes, banks, holidays, company registrations, and international country indicators.
Details
BrazilDataAPI: Access Brazilian Economic, Demographic, Environmental, and Geopolitical Data via RESTful APIs and Curated Datasets
Access Brazilian Economic, Demographic, Environmental, and Geopolitical Data via RESTful APIs and Curated Datasets.
Author(s)
Maintainer: Renzo Caceres Rossi arenzocaceresrossi@gmail.com
See Also
Useful links:
Brazilian Female Demographics & Mortality (1991-2000)
Description
This dataset, Brasil_females_df, is a data frame containing population counts and mortality information for females in Brazil, disaggregated by federal states and abridged age groups, for the years 1991 and 2000. The dataset includes 486 observations and 8 variables. Population counts are reported for both years, and deaths are given as average counts over the intercensal period. Age groups follow the pattern 0, 1, 5, ..., 75, with an open age group at 80+. A total of 53 Brazilian states are represented.
Usage
data(Brasil_females_df)
Format
A data frame with 486 observations and 8 variables:
- cod
Integer code identifying each federal state
- pop1
Population count in 1991 (integer)
- pop2
Population count in 2000 (integer)
- deaths
Average number of deaths during the intercensal period (numeric)
- year1
First census year (1991; integer)
- year2
Second census year (2000; integer)
- age
Abridged age group (integer values like 0, 1, 5, ..., 75; open age group at 80)
- sex
Sex identifier; all values are "f" (character)
Details
The dataset name has been kept as 'Brasil_females_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the BrazilDataAPI package and assists users in identifying its specific characteristics. The suffix 'df' indicates that the dataset is a data frame. The original content has not been modified in any way.
Source
Data taken from the DDM package version 1.0-0
Brazilian Male Demographics & Mortality (1980-1991)
Description
This dataset, Brasil_males_df, is a data frame containing population counts and mortality information for males in Brazil, disaggregated by federal states and abridged age groups, for the years 1980 and 1991. The dataset includes 486 observations and 8 variables. Population counts are reported for both years, and deaths are given as average counts over the intercensal period. Age groups follow the pattern 0, 1, 5, ..., 75, with an open age group at 80+. A total of 53 Brazilian states are represented.
Usage
data(Brasil_males_df)
Format
A data frame with 486 observations and 8 variables:
- cod
Integer code identifying each federal state
- pop1
Population count in 1980 (integer)
- pop2
Population count in 1991 (integer)
- deaths
Average number of deaths during the intercensal period (numeric)
- year1
First census year (1980; integer)
- year2
Second census year (1991; integer)
- age
Abridged age group (integer values like 0, 1, 5, ..., 75; open age group at 80)
- sex
Sex identifier; all values are "m" (character)
Details
The dataset name has been kept as 'Brasil_males_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the BrazilDataAPI package and assists users in identifying its specific characteristics. The suffix 'df' indicates that the dataset is a data frame. The original content has not been modified in any way.
Source
Data taken from the DDM package version 1.0-0
Films Shown at Brazilian Film Festivals (2007–2011)
Description
This dataset, Brazil_films_df, is a data frame containing information on films shown at five different film festivals in Brazil from 2007 to 2011. The dataset includes 25 observations and 6 variables, summarizing the number of films, directors, male and female directors, and regional categories for each year.
Usage
data(Brazil_films_df)
Format
A data frame with 25 observations and 6 variables:
- year
Year of the film festival (integer)
- regE
Festival region (factor with 5 levels)
- F
Number of films shown (integer)
- D
Number of directors (integer)
- MD
Number of male directors (integer)
- WD
Number of female directors (integer)
Details
The dataset name has been kept as 'Brazil_films_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the BrazilDataAPI package and assists users in identifying its specific characteristics. The suffix 'df' indicates that the dataset is a data frame. The original content has not been modified in any way.
Source
Data taken from the bpca package version 1.3-6
Yellow Fever Outbreak in Brazil (Dec 2016 – May 2017)
Description
This dataset, Yellow_Fever_list, is a list object containing information on the flow of Yellow Fever cases between five Brazilian states during the outbreak period from December 2016 to May 2017. The data include epidemiological statistics such as the number of cases, population, dates of first and last recorded cases, as well as travel-related matrices indicating disease importation and exportation.
Usage
data(Yellow_Fever_list)
Format
A list with 4 elements:
- states
A data frame with 5 observations on 5 variables, including location code, population, number of cases, and dates of first and last reported cases
- T_D
A 5x10 numeric matrix of travel destinations (disease importation probabilities)
- T_O
A 5x10 numeric matrix of travel origins (disease exportation probabilities)
- length_of_stay
A named numeric vector of average length of stay per destination
Details
The dataset name has been kept as 'Yellow_Fever_list' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the BrazilDataAPI package and assists users in identifying its specific characteristics. The suffix 'list' indicates that the dataset is a list object. The original content has not been modified in any way.
Source
Data taken from the epiflows package version 0.2.1
Get List of Banks in Brazil
Description
This function retrieves the list of all banks in Brazil from the BrasilAPI endpoint: 'https://brasilapi.com.br/api/banks/v1'. The response includes key details such as bank code, name, and ISPB (identificador do sistema de pagamentos).
Usage
get_brazil_banks()
Value
A tibble (data frame) with the following columns:
-
code
: Bank code (integer). -
name
: Short name of the bank. -
fullName
: Full registered name of the bank. -
ispb
: ISPB code (Identificador do Sistema de Pagamentos Brasileiros).
Note
Requires internet connection. The function pulls data in real time from BrasilAPI.
See Also
Examples
## Not run:
banks <- get_brazil_banks()
head(banks)
## End(Not run)
Get Address Information by Brazilian CEP (Postal Code)
Description
This function retrieves detailed address information for a given Brazilian postal code (CEP) using the BrasilAPI endpoint.
Usage
get_brazil_cep(cep)
Arguments
cep |
A valid Brazilian postal code (CEP) with 8 digits (e.g., "89010025"). |
Details
Example URL format: https://brasilapi.com.br/api/cep/v1/89010025
Replace 89010025
with any valid Brazilian postal code (CEP).
The function sends a GET request to the BrasilAPI CEP endpoint. If the request
is successful and the response contains the expected fields, it returns a
structured tibble. Otherwise, a message is displayed and NULL
is returned.
Value
A data frame (tibble) with the following columns:
-
cep
: The CEP (postal code). -
state
: State abbreviation (e.g., SP, RJ). -
city
: City or municipality. -
neighborhood
: Neighborhood. -
street
: Street name. -
service
: Name of the API service used.
Note
Requires an internet connection. Make sure the CEP is correctly formatted (only digits, 8 characters).
See Also
Examples
## Not run:
# Look up information for a specific CEP
get_brazil_cep("89010025")
## End(Not run)
Get Company Information by CNPJ (Brazil)
Description
This function retrieves public company registration data in Brazil by querying the BrasilAPI endpoint.
Usage
get_brazil_cnpj(cnpj)
Arguments
cnpj |
A valid CNPJ number as a string (only digits, no punctuation). |
Details
Example URL format: https://brasilapi.com.br/api/cnpj/v1/19131243000197
Replace 19131243000197
with any valid Brazilian CNPJ number.
It returns a tibble with essential information such as the company's legal name, trade name, address, primary activity, and registration status.
The function makes an HTTP GET request to the BrasilAPI CNPJ endpoint and processes the JSON response into a structured tibble. It only returns fields that are essential and informative for the user.
Value
A tibble with selected essential fields:
-
cnpj
: CNPJ identifier. -
razao_social
: Legal name. -
nome_fantasia
: Trade name. -
capital_social
: Registered capital (numeric). -
data_inicio_atividade
: Start date of activities. -
cnae_fiscal_descricao
: Main economic activity. -
natureza_juridica
: Legal nature. -
descricao_situacao_cadastral
: Registration status. -
municipio
: City. -
uf
: State. -
cep
: Postal code. -
logradouro
: Address (street). -
numero
: Address number. -
bairro
: Neighborhood.
Note
Requires internet connection. The function returns NULL
if the CNPJ is invalid or not found.
See Also
Examples
## Not run:
get_brazil_cnpj("19131243000197")
## End(Not run)
Get Municipalities of a Brazilian State from IBGE
Description
This function retrieves a list of municipalities from the Brazilian IBGE API using the state abbreviation (UF). It includes the name of each municipality and its official IBGE code.
Usage
get_brazil_municipalities(uf)
Arguments
uf |
A two-letter string representing the Brazilian state abbreviation (e.g., "SP", "RJ", "BA"). |
Details
The function sends a GET request to the BrasilAPI IBGE endpoint. If the UF (state abbreviation)
is invalid or not recognized, the function returns NULL
with an appropriate message.
Value
A data frame (tibble) with the following columns:
-
nome
: Name of the municipality. -
codigo_ibge
: Official IBGE code for the municipality (as character).
Note
Requires internet access. Official IBGE codes are widely used for geostatistical analysis and identification of Brazilian municipalities.
See Also
Examples
## Not run:
municipalities_sp <- get_brazil_municipalities("SP")
head(municipalities_sp)
## End(Not run)
Get Specific Brazilian Economic Rate by Name
Description
This function retrieves the value of a specific Brazilian economic rate (e.g., "CDI", "Selic", "IPCA") from the BrasilAPI endpoint.
Usage
get_brazil_rate_name(rate_name)
Arguments
rate_name |
A character string indicating the rate to retrieve. Valid examples include
|
Value
A tibble with two columns: nome
(name of rate) and valor
(numeric value).
See Also
get_brazil_rates
to retrieve all rates at once.
Examples
## Not run:
get_brazil_rate_name("CDI")
get_brazil_rate_name("Selic")
get_brazil_rate_name("IPCA")
## End(Not run)
Get Official Interest Rates and Indexes from Brazil
Description
This function retrieves official interest rates and indexes from the BrazilAPI endpoint: 'https://brasilapi.com.br/api/taxas/v1'.
Usage
get_brazil_rates()
Value
A tibble with the following columns:
-
nome
: Name or acronym of the rate/index. -
valor
: Current value of the rate/index.
See Also
Examples
## Not run:
taxas <- get_brazil_rates()
print(taxas)
## End(Not run)
Get Vehicle Brands from BrasilAPI (FIPE Data)
Description
This function retrieves a list of vehicle brands in Brazil using the BrasilAPI endpoint, which provides data sourced from FIPE (Fundação Instituto de Pesquisas Econômicas). The user must specify the type of vehicle: '"carros"', '"motos"', or '"caminhoes"'.
Usage
get_brazil_vehicle_brands(tipo_veiculo)
Arguments
tipo_veiculo |
A string indicating the type of vehicle. Must be one of '"carros"', '"motos"', or '"caminhoes"'. |
Details
This function sends a GET request to the BrasilAPI endpoint and parses the list of vehicle brands.
If the API returns an error (e.g., invalid vehicle type), the function will return NULL
.
Value
A tibble (data frame) with the following columns:
-
nome
: Brand name. -
valor
: FIPE code of the brand.
Note
Requires internet connection. Only supports Brazilian vehicle types defined by BrasilAPI.
See Also
Examples
## Not run:
# Retrieve list of car brands
cars <- get_brazil_vehicle_brands("carros")
head(cars)
## End(Not run)
Get Key Country Information from the REST Countries API
Description
Retrieves selected, essential information about Brazil or any other country by its full name. The data is retrieved from the REST Countries API. See the API documentation at https://restcountries.com/. Example API usage: https://restcountries.com/v3.1/name/brazil?fullText=true.
Usage
get_country_info(name)
Arguments
name |
Full country name (common or official). For example: "Brazil", "Peru", "France". |
Details
This function returns readable details such as the country's common and official name, capital, region, subregion, population, area, and official languages.
The function sends a GET request to the REST Countries API. If the request is successful (HTTP 200),
it parses the JSON and extracts the key fields. If the country is not found or there's an error,
the function returns NULL
with a user-friendly message.
Value
A data frame with 8 columns:
-
name_common
: Common name of the country. -
name_official
: Official name of the country. -
capital
: Capital city. -
region
: Geographic region. -
subregion
: Subregion. -
population
: Total population. -
area
: Total area in square kilometers. -
languages
: Official languages, separated by commas.
See Also
Examples
## Not run:
get_country_info("Brazil")
get_country_info("Japan")
get_country_info("France")
## End(Not run)
Monthly Average Heights of the Rio Negro at Manaus (1903–1992)
Description
This dataset, manaus_ts, is a univariate time series of monthly average river heights of the Rio Negro at Manaus. The series contains 1080 observations spanning 90 years, from January 1903 to December 1992. Each value represents the monthly average of the daily stages (heights) of the Rio Negro. Manaus is located 18 km upstream from the confluence of the Rio Negro with the Amazon River, and due to the minimal slope and flatland affluents, the measurements can be considered a good approximation of the water level at the confluence.
Usage
data(manaus_ts)
Format
A univariate time series of class ts
with 1080 monthly observations from 1903 to 1992:
- values
Monthly average river heights (numeric)
Details
The dataset name has been kept as 'manaus_ts' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the BrazilDataAPI package and assists users in identifying its specific characteristics. The suffix 'ts' indicates that the dataset is a time series object. The original content has not been modified in any way.
Source
Data taken from the boot package version 1.3-31
Emission Factors from the Environmental Agency of São Paulo (CETESB)
Description
This dataset, sp_emission_factors_df, is a data frame containing emission factors from the Environmental Agency of São Paulo (CETESB), including equivalencies with European (EURO) vehicle emission standards. The dataset includes 288 observations and 10 variables, covering pollutants, vehicle age and type, and classification systems such as Proconve and EURO for both light-duty and heavy-duty vehicles.
Usage
data(sp_emission_factors_df)
Format
A data frame with 288 observations and 10 variables:
- Age
Vehicle age (integer)
- Year
Reference year (integer)
- Pollutant
Pollutant type (character)
- Proconve_LDV
Proconve classification for light-duty vehicles (factor)
- t_Euro_LDV
Temporal equivalence to EURO for light-duty vehicles (factor)
- Euro_LDV
EURO standard classification for light-duty vehicles (factor)
- Proconve_HDV
Proconve classification for heavy-duty vehicles (factor)
- Euro_HDV
EURO standard classification for heavy-duty vehicles (factor)
- PC_G
Emission factor (numeric)
- LT
Lifetime or load factor (numeric)
Details
The dataset name has been kept as 'sp_emission_factors_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the BrazilDataAPI package and assists users in identifying its specific characteristics. The suffix 'df' indicates that the dataset is a data frame. The original content has not been modified in any way.
Source
Data taken from the vein package version 1.1.3
View Available Datasets in BrazilDataAPI
Description
This function lists all datasets available in the 'BrazilDataAPI' package. If the 'BrazilDataAPI' package is not loaded, it stops and shows an error message. If no datasets are available, it returns a message and an empty vector.
Usage
view_datasets_BrazilDataAPI()
Value
A character vector with the names of the available datasets. If no datasets are found, it returns an empty character vector.
Examples
if (requireNamespace("BrazilDataAPI", quietly = TRUE)) {
library(BrazilDataAPI)
view_datasets_BrazilDataAPI()
}