## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----eval = FALSE-------------------------------------------------------------
# # From CRAN (when available):
# install.packages("raisr")
# 
# # Development version:
# # remotes::install_github("StrategicProjects/raisr")

## -----------------------------------------------------------------------------
library(raisr)

f <- system.file("extdata", "2024", "RAIS_VINC_PUB_NORDESTE_sample.7z", package = "raisr")
x <- rais_read(f, verbose = FALSE)
x

## -----------------------------------------------------------------------------
rais_layout()[, c("column", "original", "type")]

## -----------------------------------------------------------------------------
pe <- rais_read(
  f,
  uf = "PE",
  columns = c("municipio", "cnae_20_subclasse", "vinculo_ativo_31_12",
              "mes_admissao", "mes_desligamento", "vl_remun_dezembro_nom"),
  verbose = FALSE
)
pe

## -----------------------------------------------------------------------------
rais_stock(pe, by = "municipio")

## -----------------------------------------------------------------------------
e <- system.file("extdata", "2023", "RAIS_ESTAB_PUB_sample.7z", package = "raisr")
rais_read(e, uf = 26, columns = c("municipio", "cnae_20_subclasse", "qtd_vinculos_ativos"),
          verbose = FALSE)

## -----------------------------------------------------------------------------
rais_files(2024, uf = "PE")
rais_files(2017, uf = c("PE", "BA"), type = c("vinculos", "estabelecimentos"))

## ----eval = FALSE-------------------------------------------------------------
# # Everything published for 2024, with sizes and dates
# rais_available(year = 2024)
# 
# # Download the NORDESTE regional file of 2024 into the cache (about 600 MB)
# rais_download(2024, uf = "PE")
# 
# # Download and read in one go: Pernambuco, three years, a few columns
# pe <- rais_fetch(2022:2024, uf = "PE",
#                  columns = c("municipio", "vinculo_ativo_31_12", "vl_remun_dezembro_nom"))
# 
# # Stock and December payroll by municipality and year
# rais_stock(pe, by = "municipio")

## ----eval = FALSE-------------------------------------------------------------
# Sys.setenv(RAISR_CACHE_DIR = "~/dados/rais")
# rais_cache_list()

