
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:
ineptr2 handles all of this through a single R6 client:
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).
# From CRAN
# install.packages("ineptr2") # Currently waiting publication on CRAN
# Development version from GitHub
# install.packages("devtools")
devtools::install_github("c-matos/ineptr2")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.