Fetch Rolling Quarter Series from SIDRA
Source:R/fetch-sidra-series.R
fetch_sidra_rolling_quarters.RdDownloads PNADC labor market indicators from IBGE's SIDRA API. These series are published as rolling quarterly averages (trimestre movel), with 12 observations per year.
Usage
fetch_sidra_rolling_quarters(
series = "all",
theme = NULL,
theme_category = NULL,
subcategory = NULL,
exclude_derived = FALSE,
use_cache = FALSE,
verbose = TRUE,
retry_failed = TRUE,
max_retries = 3
)Arguments
- series
Character vector of series names to fetch, or "all" (default) for all available series. Use
get_sidra_series_metadata()$series_nameto see available names.- theme
Character vector of themes to filter by. Valid options: "labor_market", "earnings", "demographics", "social_protection", "prices". Use NULL for no filter.
- theme_category
Character vector of theme categories to filter by. Use NULL for no filter.
- subcategory
Character vector of subcategories to filter by. Use NULL for no filter.
- exclude_derived
Logical. If TRUE, exclude series marked as derived (is_derived = TRUE in metadata). Default FALSE for backward compatibility. Derived series (rates) are computed from other series during mensalization, so excluding them saves API calls when fetching for mensalization.
- use_cache
Logical. Use cached data if available? Default FALSE. When TRUE, shows the date when data was cached (may be outdated). Use
clear_sidra_cacheto force fresh download.- verbose
Logical. Print progress messages? Default TRUE.
- retry_failed
Logical. Retry failed series downloads? Default TRUE.
- max_retries
Integer. Maximum retry attempts per series. Default 3.
Value
A data.table with columns:
- anomesfinaltrimmovel
Integer. YYYYMM of rolling quarter end month
- mesnotrim
Integer. Month position in quarter (1, 2, or 3)
- <series_name>
Numeric. One column per requested series
Details
Rolling quarters are labeled by their ending month:
201201 = Nov 2011 - Jan 2012 (mesnotrim = 1)
201202 = Dec 2011 - Feb 2012 (mesnotrim = 2)
201203 = Jan - Mar 2012 (mesnotrim = 3)
201204 = Feb - Apr 2012 (mesnotrim = 1)
etc.
The mesnotrim column indicates the month's position within its rolling
quarter, which is essential for the mensalization algorithm.
Rate Limiting
SIDRA API may have rate limits. The function includes automatic retry logic with exponential backoff for failed requests.
Internet Resource Behaviour
Per CRAN policy, this function fails gracefully when the SIDRA API is
unreachable: it emits an informative message() (no warning, no
error) and returns NULL invisibly when no series could be
fetched. Partial failures (some series succeeded) are also reported
via message(), and the result includes only the successful
series.
See also
get_sidra_series_metadata for available series names and metadata
mensalize_sidra_series to convert to exact months
Examples
# \donttest{
rq <- fetch_sidra_rolling_quarters(
series = c("taxadesocup", "popocup", "popdesocup")
)
#> Fetching 3 series from SIDRA API...
#> This may take a few minutes on first run.
#> [ 33%] Fetching popocup...
#> Failed to fetch popocup: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 67%] Fetching popdesocup...
#> Failed to fetch popdesocup: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [100%] Fetching taxadesocup...
#> Failed to fetch taxadesocup: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> fetch_sidra_rolling_quarters: no series could be fetched from the SIDRA API. Check internet connection or try again later.
head(rq)
#> NULL
# }
# \donttest{
rq_labor <- fetch_sidra_rolling_quarters(theme = "labor_market")
#> Fetching 46 series from SIDRA API...
#> This may take a few minutes on first run.
#> [ 2%] Fetching taxapartic...
#> Failed to fetch taxapartic: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 4%] Fetching nivelocup...
#> Failed to fetch nivelocup: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 7%] Fetching niveldesocup...
#> Failed to fetch niveldesocup: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 9%] Fetching popnaforca...
#> Failed to fetch popnaforca: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 11%] Fetching popocup...
#> Failed to fetch popocup: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 13%] Fetching popdesocup...
#> Failed to fetch popdesocup: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20003 ms: Timeout was reached
#> [ 15%] Fetching popforadaforca...
#> Failed to fetch popforadaforca: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 17%] Fetching taxadesocup...
#> Failed to fetch taxadesocup: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 20%] Fetching perccontribprev...
#> Failed to fetch perccontribprev: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 22%] Fetching taxacombdesosub...
#> Failed to fetch taxacombdesosub: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 24%] Fetching taxacombdesopot...
#> Failed to fetch taxacombdesopot: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 26%] Fetching taxacompsubutlz...
#> Failed to fetch taxacompsubutlz: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 28%] Fetching taxasubocuphoras...
#> Failed to fetch taxasubocuphoras: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 30%] Fetching percdesalento...
#> Failed to fetch percdesalento: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20003 ms: Timeout was reached
#> [ 33%] Fetching subocuphoras...
#> Failed to fetch subocuphoras: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20003 ms: Timeout was reached
#> [ 35%] Fetching forcapotencial...
#> Failed to fetch forcapotencial: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 37%] Fetching forcaampliada...
#> Failed to fetch forcaampliada: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 39%] Fetching desalentado...
#> Failed to fetch desalentado: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 41%] Fetching empregado...
#> Failed to fetch empregado: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 43%] Fetching empregpriv...
#> Failed to fetch empregpriv: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 46%] Fetching empregprivcomcart...
#> Failed to fetch empregprivcomcart: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 48%] Fetching empregprivsemcart...
#> Failed to fetch empregprivsemcart: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 50%] Fetching empregpubl...
#> Failed to fetch empregpubl: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 52%] Fetching empregpublcomcart...
#> Failed to fetch empregpublcomcart: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 54%] Fetching empregpublsemcart...
#> Failed to fetch empregpublsemcart: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 57%] Fetching estatutmilitar...
#> Failed to fetch estatutmilitar: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 59%] Fetching domestico...
#> Failed to fetch domestico: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 61%] Fetching domesticocomcart...
#> Failed to fetch domesticocomcart: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 63%] Fetching domesticosemcart...
#> Failed to fetch domesticosemcart: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20003 ms: Timeout was reached
#> [ 65%] Fetching empregador...
#> Failed to fetch empregador: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20001 ms: Timeout was reached
#> [ 67%] Fetching empregadorcomcnpj...
#> Failed to fetch empregadorcomcnpj: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 70%] Fetching empregadorsemcnpj...
#> Failed to fetch empregadorsemcnpj: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 72%] Fetching contapropria...
#> Failed to fetch contapropria: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 74%] Fetching contapropriacomcnpj...
#> Failed to fetch contapropriacomcnpj: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 76%] Fetching contapropriasemcnpj...
#> Failed to fetch contapropriasemcnpj: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20003 ms: Timeout was reached
#> [ 78%] Fetching trabfamauxiliar...
#> Failed to fetch trabfamauxiliar: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20003 ms: Timeout was reached
#> [ 80%] Fetching agropecuaria...
#> Failed to fetch agropecuaria: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20003 ms: Timeout was reached
#> [ 83%] Fetching industria...
#> Failed to fetch industria: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 85%] Fetching construcao...
#> Failed to fetch construcao: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20001 ms: Timeout was reached
#> [ 87%] Fetching comercio...
#> Failed to fetch comercio: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 89%] Fetching transporte...
#> Failed to fetch transporte: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 91%] Fetching alojaliment...
#> Failed to fetch alojaliment: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 93%] Fetching infcomfinimobadm...
#> Failed to fetch infcomfinimobadm: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 96%] Fetching adminpublica...
#> Failed to fetch adminpublica: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [ 98%] Fetching outroservico...
#> Failed to fetch outroservico: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20002 ms: Timeout was reached
#> [100%] Fetching servicodomestico...
#> Failed to fetch servicodomestico: Timeout was reached [servicodados.ibge.gov.br]:
#> Failed to connect to servicodados.ibge.gov.br port 443 after 20003 ms: Timeout was reached
#> fetch_sidra_rolling_quarters: no series could be fetched from the SIDRA API. Check internet connection or try again later.
# }