Package 'istatR'

Title: Interface to the Italian National Institute of Statistics ('ISTAT') API
Description: Provides an interface to the 'ISTAT' 'SDMX' RESTful API <https://esploradati.istat.it/SDMXWS/rest/>. Allows users to discover available datasets, explore their structure and dimensions, and retrieve statistical data from the Italian National Institute of Statistics. Based on the Python 'istatapi' package by Jacopo Attolini.
Authors: Juan Ignacio Fulponi [aut, cre]
Maintainer: Juan Ignacio Fulponi <[email protected]>
License: Apache License (>= 2)
Version: 0.1.0
Built: 2026-06-03 08:45:59 UTC
Source: https://github.com/jfulponi/istatr

Help Index


List all available ISTAT datasets

Description

Retrieves a list of all available datasets (dataflows) from the ISTAT API.

Usage

all_available()

Value

A tibble with the following columns:

df_id

Dataflow ID

version

Dataset version

df_description

English description of the dataset

df_structure_id

Data structure definition ID

Examples

## Not run: 
# Get all available datasets
datasets <- all_available()
head(datasets)

## End(Not run)

ISTAT API Base Functions

Description

Core functions for communicating with the ISTAT SDMX REST API


Get information about dataset dimensions

Description

Returns information about the dimensions of a dataset, including their positions and associated codelists.

Usage

dimensions_info(dataset, include_descriptions = TRUE)

Arguments

dataset

An istat_dataset object

include_descriptions

Logical; whether to include dimension descriptions (default: TRUE)

Value

A tibble with dimension information

Examples

## Not run: 
ds <- istat_dataset("139_176")
dimensions_info(ds)

## End(Not run)

ISTAT Dataset Discovery Functions

Description

Functions for discovering and exploring ISTAT datasets


Get all available values for all dimensions

Description

Uses the availableconstraint endpoint to get all valid values for each dimension. This is more accurate than getting values from codelists as it reflects actual data availability.

Usage

get_available_values(dataset)

Arguments

dataset

An istat_dataset object

Value

A named list where each element contains a tibble of available values for that dimension

Examples

## Not run: 
ds <- istat_dataset("139_176")
available <- get_available_values(ds)
available$FREQ  # Available frequency values

## End(Not run)

Retrieve data from an ISTAT dataset

Description

Fetches data from an ISTAT dataset using the currently set filters. The data is returned as a tibble with the TIME_PERIOD column converted to Date format and sorted in ascending order.

Usage

get_data(
  dataset,
  start_period = NULL,
  end_period = NULL,
  last_n_observations = NULL
)

Arguments

dataset

An istat_dataset object with filters set

start_period

Optional start date for filtering (format: YYYY-MM-DD or YYYY)

end_period

Optional end date for filtering (format: YYYY-MM-DD or YYYY)

last_n_observations

Optional integer to get only the last N observations

Value

A tibble containing the requested data with columns including:

DATAFLOW

Dataset identifier

FREQ

Frequency

TIME_PERIOD

Time period (as Date)

OBS_VALUE

Observation value

...

Additional dimension and metadata columns

Examples

## Not run: 
# Create and configure dataset
ds <- istat_dataset("139_176")
ds <- set_filters(ds,
  FREQ = "M",
  TIPO_DATO = c("ISAV", "ESAV"),
  PAESE_PARTNER = "WORLD"
)

# Get all data
data <- get_data(ds)

# Get data for a specific time range
data <- get_data(ds, start_period = "2020-01-01", end_period = "2023-12-31")

# Get only the last 12 observations
data <- get_data(ds, last_n_observations = 12)

## End(Not run)

Get available values for a dimension

Description

Retrieves all available values for a specific dimension of a dataset.

Usage

get_dimension_values(dataset, dimension_id)

Arguments

dataset

An istat_dataset object

dimension_id

The ID of the dimension

Value

A tibble with columns:

id

Value ID/code

name

Human-readable name (English)

Examples

## Not run: 
ds <- istat_dataset("139_176")
get_dimension_values(ds, "TIPO_DATO")

## End(Not run)

Create an ISTAT dataset object

Description

Creates a dataset object for a specific ISTAT dataflow. This object can be used to explore the dataset's structure, dimensions, and available values, and to set filters before retrieving data.

Usage

istat_dataset(dataflow_identifier)

Arguments

dataflow_identifier

Either a dataflow ID (e.g., "139_176"), a structure ID, or an exact dataset description

Value

A list with class "istat_dataset" containing:

df_id

Dataflow ID

version

Dataset version

df_description

Dataset description

df_structure_id

Data structure definition ID

dimensions

Named list of dimension information

filters

Named list of current filters (initialized to "." for all)

Examples

## Not run: 
# Create dataset by ID
ds <- istat_dataset("139_176")

# View dimensions
dimensions_info(ds)

# Get available values for a dimension
get_dimension_values(ds, "TIPO_DATO")

# Set filters
ds <- set_filters(ds, FREQ = "M", TIPO_DATO = c("ISAV", "ESAV"))

## End(Not run)

Quick data retrieval

Description

A convenience function that combines creating a dataset, setting filters, and retrieving data in one call.

Usage

istat_get(
  dataflow_id,
  ...,
  start_period = NULL,
  end_period = NULL,
  last_n_observations = NULL
)

Arguments

dataflow_id

Dataflow ID (e.g., "139_176")

...

Named filter arguments (dimension_id = value)

start_period

Optional start date

end_period

Optional end date

last_n_observations

Optional integer to get only the last N observations

Value

A tibble containing the requested data

Examples

## Not run: 
# Quick retrieval with filters
data <- istat_get(
  "139_176",
  FREQ = "M",
  TIPO_DATO = "ISAV",
  PAESE_PARTNER = "WORLD",
  start_period = "2020-01-01"
)

## End(Not run)

Get or set the API timeout

Description

The ISTAT API can be slow to respond, especially for large queries. This function allows you to get or set the timeout value in seconds. The default timeout is 300 seconds (5 minutes).

Usage

istat_timeout(seconds = NULL)

Arguments

seconds

Optional. If provided, sets the timeout to this value in seconds. If NULL (default), returns the current timeout value.

Value

If seconds is NULL, returns the current timeout value. If seconds is provided, invisibly returns the previous timeout value.

Examples

# Get current timeout
istat_timeout()

# Set timeout to 10 minutes
istat_timeout(600)

# Set timeout back to default
istat_timeout(300)

Print method for istat_dataset

Description

Print method for istat_dataset

Usage

## S3 method for class 'istat_dataset'
print(x, ...)

Arguments

x

An istat_dataset object

...

Additional arguments (ignored)

Value

Invisibly returns the input


Reset all filters to default (all values)

Description

Reset all filters to default (all values)

Usage

reset_filters(dataset)

Arguments

dataset

An istat_dataset object

Value

The modified istat_dataset object with all filters reset to "."

Examples

## Not run: 
ds <- istat_dataset("139_176")
ds <- set_filters(ds, FREQ = "M")
ds <- reset_filters(ds)  # All filters back to "."

## End(Not run)

ISTAT Data Retrieval Functions

Description

Functions for retrieving data from ISTAT datasets


Search for datasets by keyword

Description

Searches available ISTAT datasets by keyword in their description. The search is case-insensitive.

Usage

search_dataset(keyword)

Arguments

keyword

Character string to search for in dataset descriptions

Value

A tibble with matching datasets (same columns as all_available())

Examples

## Not run: 
# Search for datasets related to imports
import_datasets <- search_dataset("import")

# Search for population datasets
pop_datasets <- search_dataset("population")

## End(Not run)

Set filters for a dataset

Description

Sets dimension filters that will be used when retrieving data. Filter names should match dimension IDs (case-insensitive).

Usage

set_filters(dataset, ...)

Arguments

dataset

An istat_dataset object

...

Named arguments where names are dimension IDs and values are either single values or character vectors for multiple values. Use "." to select all values for a dimension.

Value

The modified istat_dataset object

Examples

## Not run: 
ds <- istat_dataset("139_176")

# Set single values
ds <- set_filters(ds, FREQ = "M", PAESE_PARTNER = "WORLD")

# Set multiple values
ds <- set_filters(ds, TIPO_DATO = c("ISAV", "ESAV"))

## End(Not run)

ISTAT API Utility Functions

Description

XML parsing and helper functions