Ir al contenido

Downloads the module if needed (see fa_download()), unzips it next to the zip file and reads one data file. SPSS and Stata files keep their variable and value labels (through haven). CSV files from INEI come in Latin-1 and are converted to UTF-8; the separator (,, or ; with decimal commas as in the ENAHO 2025) is detected, and code columns (UBIGEO, CCDD, CCPP, CCDI, IRUC, NSEGM) are kept as text so no leading zero is lost. DBF files (ESCALE before 2017 and the INEI DBF format) are read with the foreign package.

Uso

fa_read(
  survey,
  year,
  module,
  file = NULL,
  format = "auto",
  series = NULL,
  cache = fa_cache(),
  lower = TRUE,
  period = NULL,
  cols = NULL
)

Argumentos

survey

Short name, for example "enaho". See fa_surveys().

year

One year.

module

One module code.

file

Part of the file name to read, when the module has several data files (e.g. "Sumaria-2024"). A regular expression.

format

"auto" uses the format of the verified copy, or else the first of STATA, SPSS, CSV and DBF that the module has. Stata comes first because it is read exactly, with labels, and quickly; INEI's CSV files can have line breaks inside text answers. You can also ask for one of those formats.

series

For sources with several series, e.g. "panel" in ENAHO.

cache

Cache folder, see fa_cache().

lower

Turn variable names to lower case, so SPSS and Stata files look the same.

period

For sources with several files per year, the period shown by fa_catalog(), e.g. "Anual - (Ene-Dic)" in EPEN. A regular expression.

cols

Variables to read, in any case. NULL reads them all.

Valor

A data frame (a tibble for SPSS and Stata files).

Detalles

With cols only those variables are read. The module is still downloaded whole, because INEI serves nothing smaller, but reading a few columns of a wide file is several times faster and uses a fraction of the memory. fa_variables() lists the names. CSV files are read with data.table when it is installed and with base R otherwise; options(faperu.csv_engine = "base") forces base R.

For the 2017 Census use fa_redatam().

Ejemplos

if (FALSE) { # \dontrun{
s <- fa_read("enaho", 2024, "34", file = "Sumaria-2024\\.")
s <- fa_read("enaho", 2024, "34", file = "Sumaria-2024\\.",
             cols = c("conglome", "vivienda", "hogar", "pobreza", "factor07"))
} # }