An R6 class providing access to the Statistics Portugal (INE) API. Holds configuration state (language, caching preferences) and provides methods for retrieving data, metadata, and indicator catalog.
See INEClient-fields for configurable fields (language,
caching, timeouts, etc.).
Data
get_data(indicator, row_limit, ...)Retrieve tidy data for an indicator, with automatic chunking and optional caching.
download_data(indicator, row_limit, ...)Download data to the file cache without loading into memory.
load_raw_data(indicator)Load previously downloaded raw JSON data from the file cache.
preview_chunks(indicator, row_limit, ...)Preview how many API chunks a download would require.
Metadata
get_metadata(indicator)Get cleaned metadata for an indicator.
info(indicator)Print a summary of an indicator's key properties.
get_dim_info(indicator)Get dimension descriptions.
get_dim_values(indicator, dims)Get possible values for all dimensions.
is_valid(indicator)Check if an indicator exists.
is_updated(indicator, last_updated, metadata)Check if an indicator has been updated since last download.
Catalog
get_catalog()Download and parse the full indicator catalog (~10 min).
download_catalog()Download the catalog to the file cache.
Cache
list_cached()List indicators present in the file cache.
clear_cache(indicator)Clear cached files.
See also
INEClient-fields for field descriptions.
Active bindings
langLanguage code (
"PT"or"EN").use_cacheWhether caching is enabled.
cache_dirCache directory path, or
NULLfor default.row_limitDefault maximum output rows per API request.
max_retriesMaximum retry attempts for chunk downloads.
progress_intervalPrint progress every N chunks during downloads.
timeoutTimeout in seconds for API requests.
Methods
Method new()
Create a new INE API client.
Usage
INEClient$new(
lang = "PT",
use_cache = FALSE,
cache_dir = NULL,
row_limit = 1000000L,
max_retries = 3L,
progress_interval = 10L,
timeout = 300
)Arguments
langLanguage code:
"PT"(default) or"EN".use_cacheLogical. Whether to cache API responses. Default
FALSE.cache_dirCharacter or
NULL. Cache directory path. IfNULL(default), usestools::R_user_dir("ineptr2", "cache").row_limitInteger. Default maximum output rows per API request. Default
1000000L.max_retriesInteger. Maximum retry attempts for failed chunk downloads. Default
3L.progress_intervalInteger. Print a progress message every N chunks during downloads. Default
10L.timeoutNumeric. Timeout in seconds for API requests (metadata and data endpoints). Default
300(5 minutes). The catalog endpoint uses a separate, longer timeout.
Method get_data()
Retrieve tidy data for an indicator.
Arguments
indicatorINE indicator ID as a 7-digit string. Example:
"0010003".row_limitInteger or
NULL. Maximum output rows per API request before splitting into multiple calls. IfNULL(default), uses the client'srow_limitfield. See Details....Dimension filters. Each argument should be named
dimN(where N is the dimension number) with a character vector of values. Omitted dimensions include all values.
Details
Row limit and chunking
The INE API limits each request to 1 000 000 output rows, counted
as the product of unique values across all dimensions. When the
estimated row count exceeds row_limit, the request is automatically
split into smaller chunks by iterating over one or more dimensions.
If requests are timing out, try lowering row_limit (or increasing
the client's timeout field) to produce more, smaller chunks.
Method download_data()
Download data for an indicator to the file cache without
loading it into memory. Caching is temporarily enabled for the
duration of the call regardless of the client's use_cache setting.
Method load_raw_data()
Load previously downloaded raw data from the file cache
as a list of parsed JSON responses. Use download_data() first to
populate the cache.
Method get_catalog()
Get the full INE indicator catalog.
This operation is very time-consuming (~10 minutes) as it downloads
the entire catalog from the INE API. Consider using download_catalog()
to cache the result for subsequent calls.
Method download_catalog()
Download the INE indicator catalog to the file cache
without loading it into memory. This operation is time-consuming
(~10 minutes) as it downloads the entire catalog from the INE API.
Subsequent calls return the cached file immediately. Caching is
temporarily enabled for the duration of the call regardless of
the client's use_cache setting.
Method info()
Print a summary of an indicator's key properties: code, name, periodicity and time range, last update date, and a per-dimension breakdown of unique values. Labels are displayed in the client's current language.
Method get_dim_values()
Get possible values for all dimensions of an indicator.
Method preview_chunks()
Preview how many API chunks a download would require, without fetching any data. Useful for estimating download time before committing to a large request.
Method is_updated()
Check if an indicator has been updated since last download.
Arguments
indicatorINE indicator ID as a 7-digit string. Example:
"0010003".last_updatedA
Dateobject or a character string in"YYYY-MM-DD"format. If provided, takes precedence over cached metadata. IfNULL(default), the function looks for cached metadata or themetadataargument.metadataA metadata list object as returned by
get_metadata(). If provided andlast_updatedisNULL, extractsDataUltimaAtualizacao.
Method print()
Print a summary of the client configuration.
Examples
# -- Setup --
ine <- INEClient$new()
ine <- INEClient$new(lang = "EN", use_cache = TRUE)
print(ine)
#> <INEClient>
#> Language: EN
#> Cache: enabled (/home/runner/.cache/R/ineptr2)
#> Row limit: 1,000,000
#> Max retries: 3
#> Progress interval: 10
#> Timeout (s): 300
# -- Metadata --
meta <- ine$get_metadata("0010003")
#> Metadata cached at: /home/runner/.cache/R/ineptr2/ine_0010003_EN_meta.json
ine$info("0010003")
#> Using cached metadata
#> <INE Indicator>
#> Code: 0010003
#> Name: Proportion of domestic budget funded by domestic taxes (%); Annual - Budget Directorate-General (Ministry of Finance)
#> Periodicity: Annual (2010 - 2026)
#> Last updated: 2026-01-30
#> Dimensions: 2
#> dim1: Data reference period (17 values)
#> dim2: Geographic localization (Portugal) (1 values)
dims <- ine$get_dim_info("0010003")
#> Using cached metadata
vals <- ine$get_dim_values("0010003")
#> Using cached metadata
# -- Data --
df <- ine$get_data("0010003")
#> Using cached metadata
#> Downloaded chunk 1/1
#> All 1 chunks downloaded and cached
df <- ine$get_data("0010003", dim1 = "S7A2024", dim2 = c("11", "17"))
#> Using cached metadata
#> Using cached processed data
ine$preview_chunks("0008273")
#> Metadata cached at: /home/runner/.cache/R/ineptr2/ine_0008273_EN_meta.json
#> Indicator '0008273' would require 1 chunk (estimated 254,904 rows)
# -- Validation --
ine$is_valid("0010003")
#> Using cached metadata
#> [1] TRUE
ine$is_updated("0010003", last_updated = "2024-01-01")
#> [1] TRUE
# -- Cache --
ine$list_cached()
#> indicator has_metadata has_data chunks_downloaded chunks_total
#> 1 0008273 TRUE FALSE NA NA
#> 2 0010003 TRUE TRUE 1 1
#> download_complete
#> 1 FALSE
#> 2 TRUE
ine$clear_cache()
#> Cache cleared: /home/runner/.cache/R/ineptr2
