| read_cnefe | R Documentation |
Downloads and reads the CNEFE CSV file for a given IBGE municipality code, using the official IBGE FTP structure. The function relies on an internal index linking municipality codes to the corresponding ZIP URLs. Data are returned either as an Arrow Table (default) or as an sf object with SIRGAS 2000 coordinates.
read_cnefe(
code_muni = NULL,
year = 2022,
verbose = TRUE,
cache = TRUE,
cache_dir = NULL,
output = c("arrow", "sf"),
file = NULL
)
code_muni |
Integer. Seven-digit IBGE municipality code. Omit it when
reading a local file through |
year |
Integer. The CNEFE data year. Currently only 2022 is supported. Defaults to 2022. |
verbose |
Logical; if |
cache |
Logical; if |
cache_dir |
Character. Directory to use for cached downloads. If |
output |
Character. Output format. |
file |
Character. Path to a CNEFE file already on disk, read instead of
downloading. Accepts |
When output = "arrow" (default), the function does not perform any spatial
conversion and simply returns the Arrow table. When output = "sf", the
function converts the result to an sf point object using the
LONGITUDE and LATITUDE columns, with CRS EPSG:4674 (SIRGAS 2000),
keeping these columns in the final object (remove = FALSE).
If output = "arrow", an arrow::Table containing all CNEFE records for
the given municipality.
If output = "sf", an sf object with point geometry in
EPSG:4674 (SIRGAS 2000), using the LONGITUDE and LATITUDE columns.
When cache = TRUE (the default), the municipality is downloaded once and
kept as a gzipped CSV, so later calls, in this session or any other, reuse
it instead of downloading again. The cache folder is cache_dir when given,
otherwise the CNEFETOOLS_CACHE_DIR environment variable when set,
otherwise tools::R_user_dir() with which = "cache".
When cache = FALSE, the file is stored in a temporary location and
removed when the function exits.
The cache is meant to be cleared (see clear_cache_muni()). For a copy
that stays put, use cnefe_export(). The "Cache and exported copies"
article on the package website covers both.
cnefe_export() to write a municipality to a persistent, optimised
file that this function can read back through file.
# Read CNEFE data as an Arrow table
cnefe <- read_cnefe(code_muni = 2929057, cache = FALSE)
# Read a local file instead, with no network access. overwrite = TRUE because
# cnefe_export() refuses to clobber an existing export by default.
path <- cnefe_export(2929057, path = tempdir(), cache = FALSE, overwrite = TRUE)
cnefe_local <- read_cnefe(file = path)
# Read as an sf spatial object
cnefe_sf <- read_cnefe(code_muni = 2929057, output = "sf", cache = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.