| Type: | Package |
| Title: | Download Flight and Airport Data from Brazil |
| Version: | 1.3.0 |
| 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. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/ipea/flightsbr, https://ipea.github.io/flightsbr/ |
| BugReports: | https://github.com/ipea/flightsbr/issues |
| Depends: | R (≥ 4.1.0) |
| Imports: | archive, cli, data.table (≥ 1.14.0), fs, httr2 (≥ 1.1.1), lifecycle, parzer, janitor, rlang, rvest |
| Suggests: | dplyr, ggplot2 (≥ 3.3.1), rmarkdown (≥ 2.6), knitr, testthat, withr |
| VignetteBuilder: | knitr |
| Encoding: | UTF-8 |
| Config/roxygen2/version: | 8.1.1 |
| NeedsCompilation: | no |
| Packaged: | 2026-11-20 15:58:35 UTC; rafap |
| Author: | Rafael H. M. Pereira
|
| Maintainer: | Rafael H. M. Pereira <rafa.pereira.br@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-20 16:20:02 UTC |
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 rafa.pereira.br@gmail.com (ORCID)
Authors:
Rafael H. M. Pereira rafa.pereira.br@gmail.com (ORCID)
Other contributors:
Arthur Bazolli baz.arthur@gmail.com [contributor]
Ipea - Institute for Applied Economic Research [copyright holder, funder]
See Also
Useful links:
Report bugs at https://github.com/ipea/flightsbr/issues
Map airfare column names to ANAC's current names
Description
Map airfare column names to ANAC's current names
Usage
airfare_canonical_names(x)
Arguments
x |
Character vector of column names (raw or clean). |
Value
Character vector of current names, NA where a name is unknown.
Pick one airfare file per month from the hrefs of ANAC's listings
Description
ANAC's folders contain duplicates and stray files (re-uploads named
yyyymm (1).csv, .CSV.csv copies, the same month in two year folders,
.txt and .csv versions). This keeps files that follow the naming
convention and, for each month, prefers the file in the folder of its own
year, then a .csv over a .txt, then a name without (1).
Usage
airfare_files_from_hrefs(href, dom)
Arguments
href |
Character vector of hrefs (relative or absolute). |
dom |
Logical. Defaults to |
Value
A data.table with columns date (numeric) and url (the href).
Convert altitude column to numeric
Description
Altitudes are written like "512,3 m". A value with no digit before the
decimal comma (",0") is how ANAC marks a missing altitude, so it becomes
NA.
Usage
altitude_to_numeric(df)
Arguments
df |
A data.table internal to the |
Value
A "data.table" "data.frame" object, modified by reference.
Get the name of the file behind an ANAC download url
Description
Get the name of the file behind an ANAC download url
Usage
anac_file_name(file_url)
Arguments
file_url |
Character vector of urls, possibly ending in
|
Value
A character vector of file names (e.g. "basica2020-04.zip").
Build an httr2 request for an ANAC data file
Description
Build an httr2 request for an ANAC data file
Usage
anac_request(url)
Arguments
url |
String. File url. |
Value
An httr2_request.
Expand requested years into the months available on ANAC
Description
Expand requested years into the months available on ANAC
Usage
available_months(date, all_dates)
Arguments
date |
Numeric. Requested dates, either all |
all_dates |
Numeric vector of |
Value
Numeric vector of yyyymm dates. yyyymm input is returned
unchanged; yyyy input is expanded to the months of those years
that are available, with a message listing the missing months.
Config file that stores a custom cache directory
Description
Config file that stores a custom cache directory
Usage
cache_config_file()
Value
The path to the config file. The file may not exist.
Check whether date input is acceptable
Description
Check whether date input is acceptable
Usage
check_date(date, all_dates)
Arguments
date |
Numeric. Either a 6-digit date in the format |
all_dates |
Numeric vector created with the get_all_dates_available() function. |
Value
Check messages.
Examples
## Not run: if (interactive()) {
# get all dates available
all_dates <- get_all_dates_available()
# check dates
a <- check_date(200011, all_dates)
}
## End(Not run)
Check that a single argument is TRUE or FALSE
Description
Check that a single argument is TRUE or FALSE
Usage
check_flag(x, name)
Arguments
x |
The value to check. |
name |
String. The argument name, used in the error message. |
Value
TRUE invisibly, or an error.
Check whether the format of the date input is acceptable
Description
Check whether the format of the date input is acceptable
Usage
check_input_date_format(date = parent.frame()$date)
Arguments
date |
Vector. Either a 6-digit date in the format |
Value
Check messages.
Examples
## Not run: if (interactive()) {
# get all dates available
all_dates <- get_all_dates_available()
# check dates
a <- check_date(200011, all_dates)
}
## End(Not run)
Convert numeric-like columns to numeric
Description
Candidate columns are those named like nr_*, qt_*, comprimento_*,
largura_*, latgeopoint and longeopoint, except identifiers that must
keep their leading zeros (e.g. flight numbers and serial numbers). A
candidate column is converted only if every non-missing value can be read
as a number. Otherwise it is left as character, so codes such as airport
or airline identifiers are never turned into NA. A message lists the
columns that were left as character because of a few stray values.
Usage
convert_to_numeric(dt)
Arguments
dt |
A data.table with clean (lower case) column names. Modified by reference. |
Details
Values with a decimal comma ("1.500.000,00") have their thousands dots
removed; values without a comma are read as they are ("360.0").
Value
TRUE, invisibly.
Default flightsbr cache directory
Description
Default flightsbr cache directory
Usage
default_cache_dir()
Value
The path to the default cache directory,
tools::R_user_dir("flightsbr", which = "cache").
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
|
verbose |
Logical. Whether to print a message saying what was deleted.
Defaults to |
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()
Detect whether a file's header line is UTF-8 or Latin-1
Description
Detect whether a file's header line is UTF-8 or Latin-1
Usage
detect_header_encoding(path)
Arguments
path |
String. Local file path. |
Value
"UTF-8" or "Latin-1".
Download and read ANAC aircraft data
Description
Download and read ANAC aircraft data
Usage
download_aircraft_data(
file_url = parent.frame()$file_url,
showProgress = parent.frame()$showProgress,
cache = parent.frame()$cache
)
Arguments
file_url |
String. A url passed from above. |
showProgress |
Logical, passed from |
cache |
Logical, passed from |
Value
A "data.table" "data.frame" object
Examples
## Not run: if (interactive()) {
# Generate url
file_url <- get_aircraft_url(date = 202409)
# download data
a <- download_aircraft_data(file_url = file_url, showProgress = TRUE, cache = TRUE)
}
## End(Not run)
Download and read ANAC air fares data
Description
Download and read ANAC air fares data
Usage
download_airfares_data(
file_urls = parent.frame()$file_urls,
showProgress = parent.frame()$showProgress,
cache = parent.frame()$cache
)
Arguments
file_urls |
String. A url passed from above. |
showProgress |
Logical. Defaults to |
cache |
Logical. Whether the function should read cached data downloaded
previously. Defaults to |
Value
A "data.table" "data.frame" object with harmonized column
names, or NULL if the download failed.
Examples
## Not run: if (interactive()) {
files <- get_airfares_files_available(dom = TRUE)
a <- download_airfares_data(file_urls = files$url[1], showProgress = TRUE)
}
## End(Not run)
Download and read ANAC airport movement data
Description
Download and read ANAC airport movement data
Usage
download_airport_movement_data(
file_url = parent.frame()$file_url,
showProgress = parent.frame()$showProgress,
cache = parent.frame()$cache
)
Arguments
file_url |
String. A url passed from |
showProgress |
Logical, passed from |
cache |
Logical, passed from |
Value
A "data.table" "data.frame" object
Examples
## Not run: if (interactive()) {
# Generate url
file_url <- get_airport_movements_url(year=2020, month=11)
# download data
a <- download_airport_movement_data(file_url=file_url, showProgress=TRUE)
}
## End(Not run)
Download and read one ANAC airports file
Description
Download and read one ANAC airports file
Usage
download_airports_data(file_url, airport_type, showProgress, cache)
Arguments
file_url |
String. Url of the public or private airports file. |
airport_type |
String. |
showProgress |
Logical. Defaults to |
cache |
Logical. Whether the function should read cached data downloaded
previously. Defaults to |
Value
A "data.table" "data.frame" object, or NULL if the download
failed.
Download and read ANAC flight data
Description
Download and read ANAC flight data
Usage
download_flights_data(
file_url = parent.frame()$file_url,
showProgress = parent.frame()$showProgress,
select = parent.frame()$select,
cache = parent.frame()$cache
)
Arguments
file_url |
String. An ANAC url passed from above. |
showProgress |
Logical, passed from above. |
select |
A vector of column names or numbers to keep, passed from above. |
cache |
Logical, passed from above. |
Value
A "data.table" "data.frame" object
Examples
## Not run: if (interactive()) {
# Generate url
file_url <- get_flights_files_available()$url[1]
# download data
a <- download_flights_data(
file_url=file_url,
showProgress=TRUE,
select=NULL,
cache=TRUE
)
}
## End(Not run)
Download files from urls, reusing cached copies
Description
Downloads each file to a temporary .part file and only moves it to
dest_file once the download succeeded and the content is not an HTML
page. A failed or blocked request therefore never leaves a file at
dest_file, so later calls with cache = TRUE cannot read an error page as
data.
Usage
download_flightsbr_file(
file_url = parent.frame()$file_url,
showProgress = parent.frame()$showProgress,
dest_file = fs::path(flightsbr_cache_dir(), basename(file_url)),
cache = cache
)
Arguments
file_url |
String. A url passed from above. |
showProgress |
Logical, passed from above. |
dest_file |
String. Local path(s) where the file(s) are saved, one per
|
cache |
Logical, passed from above. If |
Details
With cache = TRUE, a file already at dest_file is reused unless the
ANAC server reports a different size for it (checked with a HEAD request).
If the size can't be checked (no connection, no size header, or ANAC
answers with a web page), the cached file is reused.
Value
TRUE (invisibly) if every file is available locally, otherwise
NULL (invisibly) with a message.
Examples
## Not run: if (interactive()) {
# Generate url
file_url <- get_flights_url(type='basica', date=200011)
# download data
download_flightsbr_file(file_url=file_url,
showProgress=TRUE,
dest_file = tempfile(fileext = ".zip")
)
}
## End(Not run)
Directory where flightsbr caches downloaded files
Description
The folder set with set_flightsbr_cache_dir(), or by default
tools::R_user_dir("flightsbr", which = "cache"), so cached files persist
across R sessions. See get_flightsbr_cache_dir().
Usage
flightsbr_cache_dir(create = TRUE)
Arguments
create |
Logical. Whether to create the directory if it does not
exist. Defaults to |
Value
The path to the cache directory.
Generate all months with yyyymm format for a given year
Description
Generate all months with yyyymm format for a given year
Usage
generate_all_months(date)
Arguments
date |
Numeric. 4-digit date in the format |
Value
Vector or strings.
Examples
## Not run: if (interactive()) {
# Generate all months in 2000
a <- check_date(2000)
b <- check_date(c(2000, 2005))
}
## End(Not run)
Retrieve all dates available for aircraft data from ANAC website
Description
Retrieve all dates available for aircraft data from ANAC website
Usage
get_aircraft_dates_available()
Value
Numeric vector.
Examples
## Not run: if (interactive()) {
# check dates
a <- get_aircraft_dates_available()
}
## End(Not run)
Put together the url of aircraft data files
Description
Put together the url of aircraft data files
Usage
get_aircraft_url(date = parent.frame()$date)
Arguments
date |
Numeric. Either a 6-digit date in the format |
Value
A url string.
Examples
## Not run: if (interactive()) {
# Generate url
a <- get_aircraft_url(202505)
}
## End(Not run)
Retrieve all dates available for airfares data from ANAC website
Description
Retrieve all dates available for airfares data from ANAC website
Usage
get_airfares_dates_available(dom, cache = TRUE)
Arguments
dom |
Logical. Defaults to |
cache |
Logical. Whether the function should read cached data downloaded
previously. Defaults to |
Value
Numeric vector.
Examples
## Not run: if (interactive()) {
# check dates
a <- get_airfares_dates_available(dom = TRUE)
}
## End(Not run)
Retrieve the airfare files available on the ANAC website
Description
Scrapes ANAC's directory listing (one request per year folder) and keeps
one file per month. The result is cached for the R session. If some year
folders could not be read, the result has an attribute failed_years with
those years.
Usage
get_airfares_files_available(dom, cache = TRUE)
Arguments
dom |
Logical. Defaults to |
cache |
Logical. Whether the function should read cached data downloaded
previously. Defaults to |
Value
A data.table with columns date (numeric, yyyymm) and url, or
NULL if ANAC could not be reached.
Retrieve all dates available for airport movements data
Description
Retrieve from ANAC website all dates available for airport movements data.
Usage
get_airport_movement_dates_available()
Value
Numeric vector.
Examples
## Not run: if (interactive()) {
# check dates
a <- get_airport_movement_dates_available()
}
## End(Not run)
Put together the url of airport movement data files
Description
Put together the url of airport movement data files
Usage
get_airport_movements_url(date = parent.frame()$date)
Arguments
date |
Numeric. Date of the data in the format |
Value
A url string.
Examples
## Not run: if (interactive()) {
# Generate url
a <- get_airport_movements_url(year=2000, month=11)
}
## End(Not run)
Retrieve all dates available for flights data from ANAC website
Description
Retrieve all dates available for flights data from ANAC website
Usage
get_flight_dates_available(type = NULL, cache = TRUE)
Arguments
type |
String. Whether the data set should be of the type |
cache |
Logical. Whether the function should read cached data downloaded
previously. Defaults to |
Value
Numeric vector.
Examples
## Not run: if (interactive()) {
# check dates
a <- get_flight_dates_available()
}
## End(Not run)
Retrieve flight files available from the ANAC website
Description
Retrieve flight files available from the ANAC website
Usage
get_flights_files_available(cache = TRUE)
Arguments
cache |
Logical. Whether the function should read cached data downloaded
previously. Defaults to |
Value
A data.table with columns date, type, and url.
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()
Rename airfare columns to ANAC's current names
Description
ANAC has used five different headers for the same columns over the years.
Every version is mapped to the names ANAC uses in its current files (see
airfare_col_map), so files from different periods bind into the same
columns. A leading row-index column (empty header) is dropped.
Usage
harmonize_airfare_names(dt, file_name = "")
Arguments
dt |
A data.table read from an airfare file. Modified by reference. |
file_name |
String. File name, used in error messages. |
Value
dt, invisibly.
Check whether a downloaded response is an HTML page instead of a data file
Description
Check whether a downloaded response is an HTML page instead of a data file
Usage
is_html_response(resp, path)
Arguments
resp |
An |
path |
String. Local file where the response body was written. |
Value
Logical.
Check whether local files are zip archives
Description
Reads the first two bytes of each file and checks for the zip signature
PK. ANAC sometimes returns an HTML page with HTTP status 200 instead of
the requested zip file.
Usage
is_zip_file(path)
Arguments
path |
Character vector of local file paths. |
Value
A logical vector, FALSE for files that are missing, empty, or not
zip archives.
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 |
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)
Convert latitude and longitude columns to numeric
Description
Coordinates are written in degrees, minutes and seconds (e.g.
30\u00b050'39,8"S). Some files use a decimal comma in the seconds, which
parzer can't read, so commas are replaced with dots first.
Usage
latlon_to_numeric(df)
Arguments
df |
A data.table internal to the |
Value
A "data.table" "data.frame" object, modified by reference.
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 |
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)
Turn an ANAC (gov.br) file href into a direct download url
Description
The flight file listing on gov.br links to each zip file through a relative
href (e.g. /anac/.../basica2020-04.zip) that serves an HTML landing page.
The zip file itself is served at <href>/@download/file.
Usage
normalize_anac_url(href, base)
Arguments
href |
Character vector of hrefs, relative or absolute, with or
without the |
base |
String. Url of the page the hrefs were scraped from, used to resolve relative hrefs. |
Value
A character vector of absolute urls ending in /@download/file.
Parse numbers written in Brazilian or international format
Description
Parse numbers written in Brazilian or international format
Usage
parse_number_br(x)
Arguments
x |
Character vector. |
Value
Numeric vector. Values with a decimal comma have their thousands dots removed first; values without a comma are parsed as they are.
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 |
showProgress |
Logical. Defaults to |
cache |
Logical. Whether the function should read cached data downloaded
previously. Defaults to |
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)
Read one RAB file
Description
Reads a monthly RAB file and makes the layouts ANAC has used comparable:
the registration mark column is always MARCAS (it was MARCA until early
2026), empty cells and the text "null" become NA, and quotes escaped as
"" inside a field (used in the JSON owner and operator columns) are
un-escaped.
Usage
read_aircraft_file(path, showProgress = FALSE)
Arguments
path |
String. Local file path. The file name must be |
showProgress |
Logical. Defaults to |
Value
A data.table with raw (upper case) column names and a
reference_date column.
Download aircrafts data from Brazil
Description
This function was deprecated in favor of read_aircraft() simply to
fix a typo in the function name.
Usage
read_aircrafts(date = 202001, showProgress = TRUE, cache = TRUE)
Arguments
date |
Numeric. Date of the data in the format |
showProgress |
Logical. Defaults to |
cache |
Logical. Whether the function should read cached data downloaded
previously. Defaults to |
Value
A "data.table" "data.frame" object. All columns are returned with
class of type "character".
See Also
Other download flight data:
read_aircraft(),
read_flights()
Examples
## Not run: if (interactive()) {
# Read aircraft data
aircraft <- read_aircraft(date = 202001,
showProgress = TRUE)
}
## End(Not run)
Read one airfare file and harmonize its column names
Description
Read one airfare file and harmonize its column names
Usage
read_airfare_file(path, showProgress = FALSE)
Arguments
path |
String. Local file path. |
showProgress |
Logical. Defaults to |
Value
A data.table with ANAC's current column names.
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 |
domestic |
Logical. Defaults to |
showProgress |
Logical. Defaults to |
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 |
cache |
Logical. Whether the function should read cached data downloaded
previously. Defaults to |
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 |
showProgress |
Logical. Defaults to |
cache |
Logical. Whether the function should read cached data downloaded
previously. Defaults to |
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 |
showProgress |
Logical. Defaults to |
cache |
Logical. Whether the function should read cached data downloaded
previously. Defaults to |
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)
Read the links of an ANAC directory listing page
Description
Read the links of an ANAC directory listing page
Usage
read_anac_listing(url)
Arguments
url |
String. Url of an ANAC directory listing. |
Value
A character vector of hrefs, or NULL if the page could not be
read or is not a directory listing (e.g. a page blocking the
request).
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 |
type |
String. Whether the data set should be of the type |
showProgress |
Logical. Defaults to |
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 |
cache |
Logical. Whether the function should read cached data downloaded
previously. Defaults to |
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)
Get the size of remote files with HEAD requests
Description
Get the size of remote files with HEAD requests
Usage
remote_sizes(file_url, timeout = 30)
Arguments
file_url |
Character vector of urls. |
timeout |
Numeric. Seconds to wait for each HEAD request. |
Value
A numeric vector with the remote Content-Length of each file.
NA when the request failed, the server sent no size, or the
server answered with an HTML page (ANAC's error / rate-limit page).
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 |
verbose |
Logical. Whether to print a message with the cache folder.
Defaults to |
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)
Check whether a local file starts like an HTML document
Description
Check whether a local file starts like an HTML document
Usage
starts_like_html(path)
Arguments
path |
String. Local file path. |
Value
Logical. FALSE for missing or empty files.