Convenience wrapper: caged_download() followed by caged_read() on
every archive found, with the results stacked. Missing files (for
example FOR/EXC in early 2020) are skipped with a message.
Usage
caged_fetch(
period,
uf = NULL,
files = c("MOV", "FOR", "EXC"),
columns = NULL,
cache_dir = NULL,
force = FALSE,
types = TRUE,
chunk_size = 500000L,
timeout = 900,
verbose = NULL
)Arguments
- period
Reference months in
AAAAMMformat (integer or character vector). Seecaged_periods()andcaged_available().- uf
Optional vector of state codes to keep, as IBGE two-digit numbers (for example
26for Pernambuco,c(26, 25)for Pernambuco and Paraiba).NULLkeeps every state.- files
Which files to download: any subset of
c("MOV", "FOR", "EXC").- columns
Optional character vector of columns to keep, using the normalized names listed by
caged_layout().NULLkeeps all columns. Theufcolumn is always read (it is needed for filtering) but is only returned when requested or whencolumnsisNULL.- cache_dir
Optional cache directory (see
caged_cache_dir()).- force
Re-download archives already in the cache?
- types
Convert the numeric columns of the layout (codes, salary) to integer/double? If
FALSEevery column is returned as character.- chunk_size
Number of lines parsed per chunk. Larger chunks are faster but use more memory; the default (500,000 lines) uses well under 1 GB.
- timeout
Timeout in seconds for each file. The Ministry's FTP is slow at times; the default allows 15 minutes per file.
- verbose
Emit progress messages? Defaults to
getOption("cagedr.verbose", TRUE).
Value
A tibble with the records of every archive read (see
caged_read() for the columns), or an empty tibble when nothing was
available. The attribute "download" holds the tibble returned by
caged_download(), so that not_found and error files can be
inspected.