Query the main ComexStat API endpoint to retrieve Brazilian export and import data. Allows filtering and detailing by various classifications such as NCM, Harmonized System, countries, states, etc.
Usage
comex_query(
flow = "export",
start_period,
end_period,
details = NULL,
filters = NULL,
month_detail = TRUE,
metric_fob = TRUE,
metric_kg = TRUE,
metric_statistic = FALSE,
metric_freight = FALSE,
metric_insurance = FALSE,
metric_cif = FALSE,
verbose = TRUE
)Arguments
- flow
Trade flow type: "export" or "import"
- start_period
Start period in "YYYY-MM" format (e.g., "2023-01")
- end_period
End period in "YYYY-MM" format (e.g., "2023-12")
- details
Character vector with desired detail levels. Options:
Geographic: "country", "bloc", "state", "city", "transport_mode", "customs_unit"
Products: "ncm", "hs6", "hs4", "hs2", "section"
CGCE: "cgce_n1", "cgce_n2", "cgce_n3"
SITC: "sitc_section", "sitc_chapter", "sitc_position", "sitc_subposition", "sitc_item"
ISIC: "isic_section", "isic_division", "isic_group", "isic_class"
Other: "company_size" (imports only)
- filters
Named list with filters. Use the same names as details. Example:
list(country = c("160", "249"), state = c("SP", "RJ"))- month_detail
Logical. If TRUE, detail by month. Default: TRUE
- metric_fob
Logical. If TRUE, include FOB value (US$). Default: TRUE
- metric_kg
Logical. If TRUE, include net weight in kg. Default: TRUE
- metric_statistic
Logical. If TRUE, include statistical quantity. Default: FALSE
- metric_freight
Logical. If TRUE, include freight value (US$). Default: FALSE
- metric_insurance
Logical. If TRUE, include insurance value (US$). Default: FALSE
- metric_cif
Logical. If TRUE, include CIF value (US$). Default: FALSE
- verbose
Logical. If TRUE, display progress messages. Default: TRUE
Examples
if (FALSE) { # \dontrun{
# Brazilian exports in 2023 by country (monthly by default)
comex_query(
flow = "export",
start_period = "2023-01",
end_period = "2023-12",
details = c("country")
)
# Imports 2022-2023 by NCM, filtered by country
comex_query(
flow = "import",
start_period = "2022-01",
end_period = "2023-12",
details = c("ncm", "country"),
filters = list(country = c("160", "249")),
metric_cif = TRUE
)
} # }