Overview
ineptr2 is an R client for the Statistics Portugal (INE) API. INE publishes over 13 000 statistical indicators covering demographics, health, economy, education, environment and more. The API provides programmatic access to them.
Working with the API directly can be cumbersome:
- Responses are capped at 1 million returned rows per request. Multiple requests may be required for larger indicators.
- Indicator structure (dimensions, codes, time periods) must previously known or be explored through separate metadata endpoints before you can build a more specific query.
- There is no built-in way to resume interrupted downloads or avoid redundant requests.
ineptr2 handles all of this through a single R6 client:
- Automatic chunking - splits large requests and reassembles the results transparently. The user only needs to perform one function call.
- File-based caching - stores raw chunks, processed data, and metadata on disk with resume support. If a very large indicator breaks mid-download, resume later from the break point.
- Exploration helpers - quality of life methods to inspect dimensions, preview download size, check for updates, and validate indicator codes before fetching any data.
The package targets version 2 of the INE API, which extended the functionality of the previous verison with multiple time values per request, level-based selection, and a much larger response size (from 40k to 1M rows).
Installation
# From CRAN
# install.packages("ineptr2") # Currently waiting publication on CRAN
# Development version from GitHub
# install.packages("devtools")
devtools::install_github("c-matos/ineptr2")Quick example
library(ineptr2)
ine <- INEClient$new()
# Fetch data for a small indicator
df <- ine$get_data("0010003")
head(df)
#> dim_1 geocod geodsg ind_string valor
#> 1 2010 PT Portugal 58,31 58.31
#> 2 2011 PT Portugal 60,04 60.04
#> 3 2012 PT Portugal 60,53 60.53
#> 4 2013 PT Portugal 58,92 58.92
#> 5 2014 PT Portugal 62,10 62.1
#> 6 2015 PT Portugal 61,28 61.28For larger indicators, you can filter by dimension to get only what you need:
# Resident population, year 2023, NUTS 1 regions only
df <- ine$get_data(
"0008273",
dim1 = "S7A2023",
dim2 = c("PT", "1", "2", "3"),
dim3 = "T"
)
head(df)
#> dim_1 geocod geodsg dim_3 dim_3_t dim_4 dim_4_t
#> 1 2023 2 Região Autónoma dos Açores T HM 81 70 - 74 anos
#> 2 2023 1 Continente T HM 81 70 - 74 anos
#> 3 2023 3 Região Autónoma da Madeira T HM 81 70 - 74 anos
#> 4 2023 PT Portugal T HM 81 70 - 74 anos
#> 5 2023 2 Região Autónoma dos Açores T HM 82 75 - 79 anos
#> 6 2023 1 Continente T HM 82 75 - 79 anos
#> ind_string valor
#> 1 11 003 11003
#> 2 594 627 594627
#> 3 13 513 13513
#> 4 619 143 619143
#> 5 7 893 7893
#> 6 498 889 498889Use ine$get_dim_values() to discover the valid codes for each dimension.
Learn more
- Get started — full walkthrough: creating a client, exploring indicators, downloading data, and caching.
- How caching works — chunk cache, manifests, resume support, and cache invalidation.
- What changed from ineptR — differences from the previous version.
