Package 'flightsbr'

Title: Download Flight and Airport Data from Brazil
Description: Download flight and airport data from Brazil’s Civil Aviation Agency (ANAC) <https://www.gov.br/anac/pt-br>. The data covers detailed information on aircraft, airports, and airport operations registered with ANAC. It also includes data on airfares, all international flights to and from Brazil, and domestic flights within the country.
Authors: Rafael H. M. Pereira [aut, cre] (ORCID: <https://orcid.org/0000-0003-2125-7465>), Arthur Bazolli [ctb], Ipea - Institute for Applied Economic Research [cph, fnd]
Maintainer: Rafael H. M. Pereira <[email protected]>
License: MIT + file LICENSE
Version: 1.3.0
Built: 2026-11-20 21:31:22 UTC
Source: https://github.com/cran/flightsbr

Help Index


Delete data cached by flightsbr

Description

Deletes files from the flightsbr cache folder (see get_flightsbr_cache_dir()): all cached files, or only the ones named in file.

Usage

delete_flightsbr_cache(file = NULL, verbose = TRUE)

Arguments

file

String. Names of cached files to delete, for example "basica2000-01.zip" (see list_flightsbr_cache()). If NULL (the default), all cached files are deleted.

verbose

Logical. Whether to print a message saying what was deleted. Defaults to TRUE.

Details

Only files saved directly in the cache folder are deleted. Subfolders and their content are never touched, so pointing the cache at a folder that also holds other things (see set_flightsbr_cache_dir()) can't wipe them out. The cache folder itself is removed if it ends up empty.

Value

Invisibly, the path to the cache folder.

See Also

Other Cache data: get_flightsbr_cache_dir(), list_flightsbr_cache(), set_flightsbr_cache_dir()

Examples

# delete one file
delete_flightsbr_cache("basica2000-01.zip")

# delete all cached files
delete_flightsbr_cache()

flightsbr: Download Flight and Airport Data from Brazil

Description

Download flight and airport data from Brazil’s Civil Aviation Agency (ANAC) https://www.gov.br/anac/pt-br. The data includes detailed information on all aircrafts, aerodromes, airports, and airport movements registered in ANAC, and on every international flight to and from Brazil, as well as domestic flights within the country.

Usage

Please check the vignettes and data documentation on the website.

Author(s)

Maintainer: Rafael H. M. Pereira [email protected] (ORCID)

Authors:

Other contributors:

  • Arthur Bazolli [email protected] [contributor]

  • Ipea - Institute for Applied Economic Research [copyright holder, funder]

See Also

Useful links:


Get the folder where flightsbr caches downloaded data

Description

Returns the folder used to cache data downloaded by flightsbr: the folder set with set_flightsbr_cache_dir(), possibly in a previous R session, or the default folder, tools::R_user_dir("flightsbr", which = "cache").

Usage

get_flightsbr_cache_dir()

Value

String. The path to the cache folder. The folder may not exist yet if no data has been downloaded.

See Also

Other Cache data: delete_flightsbr_cache(), list_flightsbr_cache(), set_flightsbr_cache_dir()

Examples

get_flightsbr_cache_dir()

Check the date of the latest airfare data available

Description

Check the date of the latest airfare data available

Usage

latest_airfares_date(dom = TRUE)

Arguments

dom

Logical. Defaults to TRUE download airfares of domestic flights. If FALSE, the function downloads airfares of international flights.

Value

A numeric date in the format yyyymm.

See Also

Other support function: latest_flights_date()

Examples

## Not run:  if (interactive()) {

latest_date <- latest_airfares_date()

}
## End(Not run)

Check the date of the latest flight data available

Description

Check the date of the latest flight data available

Usage

latest_flights_date()

Value

A numeric date in the format yyyymm.

See Also

Other support function: latest_airfares_date()

Examples

## Not run:  if (interactive()) {

latest_date <- latest_flights_date()

}
## End(Not run)

List the data cached by flightsbr

Description

Lists the files saved in the flightsbr cache folder (see get_flightsbr_cache_dir()).

Usage

list_flightsbr_cache(print_tree = FALSE)

Arguments

print_tree

Logical. Whether to print the content of the cache folder as a tree. Defaults to FALSE.

Value

A character vector with the paths of the cached files (invisibly when print_tree = TRUE). An empty vector if nothing is cached.

See Also

Other Cache data: delete_flightsbr_cache(), get_flightsbr_cache_dir(), set_flightsbr_cache_dir()

Examples

list_flightsbr_cache()

list_flightsbr_cache(print_tree = TRUE)

Download aircraft data from Brazil

Description

Download data of all aircraft registered in the Brazilian Aeronautical Registry (Registro Aeronáutico Brasileiro - RAB), organized by the Brazilian Civil Aviation Agency (ANAC). A description of all variables included in the data is available at https://www.gov.br/anac/pt-br/sistemas/rab.

Usage

read_aircraft(date = NULL, showProgress = TRUE, cache = TRUE)

Arguments

date

Numeric. Date of the data in the format yyyymm. Defaults to the latest date available. To download the data for all months in a year, the user can pass a 4-digit year input yyyy. The function also accepts a vector of dates, like c(202201, 202301) or c(2022, 2024).

showProgress

Logical. Defaults to TRUE display progress.

cache

Logical. Whether the function should read cached data downloaded previously. Defaults to TRUE. Downloaded files are cached in a folder that persists across R sessions (see get_flightsbr_cache_dir() and set_flightsbr_cache_dir()), and a cached file is downloaded again only if ANAC's copy has a different size. If FALSE, the function will always download the data and overwrite cached data. See list_flightsbr_cache() and delete_flightsbr_cache() to manage cached files.

Value

A ⁠"data.table" "data.frame"⁠ object. Columns of counts and measures are numeric; codes and identifiers (e.g. flight numbers, serial numbers, airport codes) are character, keeping leading zeros. A column with some values that are not numbers stays character, with a message.

See Also

Other download flight data: read_aircrafts(), read_flights()

Examples

## Not run:  if (interactive()) {
# Read aircraft data
aircraft <- read_aircraft(date = 202409,
                          showProgress = TRUE
                          )


}
## End(Not run)

Download data on airfares flights in Brazil

Description

Download data on air fares of domestic and international flights in Brazil. The data is collected by Brazil’s Civil Aviation Agency (ANAC). A description of all variables included in the data for domestic airfares is available at https://www.anac.gov.br/acesso-a-informacao/dados-abertos/areas-de-atuacao/voos-e-operacoes-aereas/tarifas-aereas-domesticas/46-tarifas-aereas-domesticas. A description of all variables included in the data for international airfares is available at https://www.gov.br/anac/pt-br/assuntos/dados-e-estatisticas/microdados-de-tarifas-aereas-comercializadas.

Usage

read_airfares(
  date = NULL,
  domestic = TRUE,
  showProgress = TRUE,
  select = NULL,
  cache = TRUE
)

Arguments

date

Numeric. Date of the data in the format yyyymm. Defaults to the latest date available. To download the data for all months in a year, the user can pass a 4-digit year input yyyy. The function also accepts a vector of dates, like c(202201, 202301) or c(2022, 2024).

domestic

Logical. Defaults to TRUE download airfares of domestic flights. If FALSE, the function downloads airfares of international flights.

showProgress

Logical. Defaults to TRUE display progress.

select

A vector of column names or positions to keep. The order that the columns passed determines the order of the columns in the result. In read_airfares(), only column names are accepted, and both current and older ANAC names work (see Details).

cache

Logical. Whether the function should read cached data downloaded previously. Defaults to TRUE. Downloaded files are cached in a folder that persists across R sessions (see get_flightsbr_cache_dir() and set_flightsbr_cache_dir()), and a cached file is downloaded again only if ANAC's copy has a different size. If FALSE, the function will always download the data and overwrite cached data. See list_flightsbr_cache() and delete_flightsbr_cache() to manage cached files.

Details

ANAC has changed the column names of these files several times. All files are returned with the names ANAC uses in its current files (nr_ano_referencia, nr_mes_referencia, sg_empresa_icao, sg_icao_origem, sg_icao_destino, nr_tarifa, nr_assentos and, for international flights, sg_icao_retorno, cd_classe_ida, cd_classe_volta), so files from different years can be combined. select accepts these names as well as older names such as "TARIFA" or "ano".

Value

A ⁠"data.table" "data.frame"⁠ object.

Examples

## Not run:  if (interactive()) {
# Read air fare data
af_201506 <- read_airfares(date = 201506, domestic = TRUE)

af_2015 <- read_airfares(date = 2015, domestic = TRUE)
}
## End(Not run)

Download airport movement data from Brazil

Description

Download airport movements data from Brazil’s Civil Aviation Agency (ANAC). The data covers all passenger, aircraft, cargo and mail movement data from airports regulated by ANAC. Data only available from March 2019 onwards. A description of all variables included in the data is available at https://www.anac.gov.br/acesso-a-informacao/dados-abertos/areas-de-atuacao/operador-aeroportuario/dados-de-movimentacao-aeroportuaria/60-dados-de-movimentacao-aeroportuaria.

Usage

read_airport_movements(date = NULL, showProgress = TRUE, cache = TRUE)

Arguments

date

Numeric. Date of the data in the format yyyymm. Defaults to the latest date available. To download the data for all months in a year, the user can pass a 4-digit year input yyyy. The function also accepts a vector of dates, like c(202201, 202301) or c(2022, 2024).

showProgress

Logical. Defaults to TRUE display progress.

cache

Logical. Whether the function should read cached data downloaded previously. Defaults to TRUE. Downloaded files are cached in a folder that persists across R sessions (see get_flightsbr_cache_dir() and set_flightsbr_cache_dir()), and a cached file is downloaded again only if ANAC's copy has a different size. If FALSE, the function will always download the data and overwrite cached data. See list_flightsbr_cache() and delete_flightsbr_cache() to manage cached files.

Value

A ⁠"data.table" "data.frame"⁠ object. Columns of counts and measures are numeric; codes and identifiers (e.g. flight numbers, serial numbers, airport codes) are character, keeping leading zeros. A column with some values that are not numbers stays character, with a message.

Examples

## Not run:  if (interactive()) {
# Read airport movement data
amov202006 <- read_airport_movements(date = 202006)

amov2020 <- read_airport_movements(date = 2020)
}
## End(Not run)

Download airports data from Brazil

Description

Download data of all airports and aerodromes registered in Brazil’s Civil Aviation Agency (ANAC). Data source: https://www.gov.br/anac/pt-br/acesso-a-informacao/dados-abertos/areas-de-atuacao/aerodromos. The data dictionary for public airports can be found at https://www.anac.gov.br/acesso-a-informacao/dados-abertos/areas-de-atuacao/aerodromos/lista-de-aerodromos-publicos-v2/70-lista-de-aerodromos-publicos-v2. The data dictionary for private airports can be found at https://www.anac.gov.br/acesso-a-informacao/dados-abertos/areas-de-atuacao/aerodromos/lista-de-aerodromos-privados-v2.

Usage

read_airports(type = "all", showProgress = TRUE, cache = TRUE)

Arguments

type

String. Whether the function should download data on all, public or private airports. Defaults to all, returning fewer columns. Downloading public and private airports separately will return the full set of columns available for each of those data sets.

showProgress

Logical. Defaults to TRUE display progress.

cache

Logical. Whether the function should read cached data downloaded previously. Defaults to TRUE. Downloaded files are cached in a folder that persists across R sessions (see get_flightsbr_cache_dir() and set_flightsbr_cache_dir()), and a cached file is downloaded again only if ANAC's copy has a different size. If FALSE, the function will always download the data and overwrite cached data. See list_flightsbr_cache() and delete_flightsbr_cache() to manage cached files.

Value

A ⁠"data.table" "data.frame"⁠ object.

Examples

## Not run:  if (interactive()) {
# Read airports data
all_airports <- read_airports(type = 'all')

public_airports <- read_airports(type = 'public')

private_airports <- read_airports(type = 'private')
}
## End(Not run)

Download flight data from Brazil

Description

Download flight data from Brazil’s Civil Aviation Agency (ANAC). The data includes detailed information on every international flight to and from Brazil, as well as domestic flights within the country. The data include flight-level information of airports of origin and destination, flight duration, aircraft type, payload, and the number of passengers, and several other variables. A description of all variables included in the data is available at https://www.gov.br/anac/pt-br/assuntos/regulados/empresas-aereas/Instrucoes-para-a-elaboracao-e-apresentacao-das-demonstracoes-contabeis/descricao-de-variaveis.

Usage

read_flights(
  date = NULL,
  type = "basica",
  showProgress = TRUE,
  select = NULL,
  cache = TRUE
)

Arguments

date

Numeric. Date of the data in the format yyyymm. Defaults to the latest available month. To download the data for all months in a year, the user can pass a 4-digit year input yyyy. The parameter also accepts a vector of dates such as c(202001, 202006, 202012).

type

String. Whether the data set should be of the type basica (flight stage, the default) or combinada (On flight origin and destination - OFOD).

showProgress

Logical. Defaults to TRUE display progress.

select

A vector of column names or positions to keep. The order that the columns passed determines the order of the columns in the result. In read_airfares(), only column names are accepted, and both current and older ANAC names work (see Details).

cache

Logical. Whether the function should read cached data downloaded previously. Defaults to TRUE. Downloaded files are cached in a folder that persists across R sessions (see get_flightsbr_cache_dir() and set_flightsbr_cache_dir()), and a cached file is downloaded again only if ANAC's copy has a different size. If FALSE, the function will always download the data and overwrite cached data. See list_flightsbr_cache() and delete_flightsbr_cache() to manage cached files.

Value

A ⁠"data.table" "data.frame"⁠ object. Columns of counts and measures are numeric; codes and identifiers (e.g. flight numbers, serial numbers, airport codes) are character, keeping leading zeros. A column with some values that are not numbers stays character, with a message.

See Also

Other download flight data: read_aircraft(), read_aircrafts()

Examples

## Not run:  if (interactive()) {
# Read flights data
f201506 <- read_flights(date = 201506)

f2015 <- read_flights(date = 2015)
}
## End(Not run)

Set the folder where flightsbr caches downloaded data

Description

flightsbr saves the files it downloads from ANAC in a cache folder, so that each file is downloaded only once, even across R sessions. This function sets which folder is used. The choice is saved and persists across R sessions.

Files already cached in the previous folder are not moved. They stay where they are until you delete them, for example with delete_flightsbr_cache() before changing the folder.

Usage

set_flightsbr_cache_dir(path = NULL, verbose = TRUE)

Arguments

path

String. The path to the folder used to cache downloaded data. If NULL (the default), flightsbr goes back to its default folder, tools::R_user_dir("flightsbr", which = "cache").

verbose

Logical. Whether to print a message with the cache folder. Defaults to TRUE.

Value

Invisibly, the path to the cache folder.

See Also

Other Cache data: delete_flightsbr_cache(), get_flightsbr_cache_dir(), list_flightsbr_cache()

Examples

# use a custom folder
set_flightsbr_cache_dir(tempdir())

# go back to the default folder
set_flightsbr_cache_dir(NULL)