R package for accessing the SITUAS (Sistema Informativo Territoriale delle Unità Amministrative e Statistiche) API - a set of APIs built by ISTAT (Italian National Institute for Statistics) to retrieve territorial codes and classifications.
Website: https://situas.istat.it/
The scope of this R package is:
The package is structured as a standard R library with CRAN standards: - use “testthat” library to develop unit tests - use “devtools” for testing and developemnt - use “roxygen” for documentation - use “renv” for installation of the environment and dependencies - use “data.table” for data management and wrangling - use vectorized code for speed and avoid for loops - use caching for off line use
# Install from GitHub
devtools::install_github("gmontaletti/situas")
# Restore package dependencies
renv::restore()
library(situas)
# Get current municipalities
comuni <- get_situas_tables(pfun = 61, date = Sys.Date())
# Get provinces
province <- get_situas_tables(pfun = 64, date = Sys.Date())
# Get regions
regioni <- get_situas_tables(pfun = 68, date = Sys.Date())The package provides functions to automatically download ISTAT administrative boundary shapefiles from the OnData repository (with fallback to the official ISTAT source).
# Download all territorial levels for 2025
download_istat_boundaries()
# Download specific territorial levels
download_istat_boundaries(
date = "2025-01-01",
territorial_levels = c("comuni", "province")
)
# Check for updates
check_boundary_updates()
# View cached boundaries
get_cached_boundaries_info()
# Clean old versions
clean_boundary_cache(keep_latest_n = 2)Data Sources: - Primary: OnData repository - Community-maintained, easier access, multiple formats - Fallback: ISTAT official - Direct from ISTAT
Cache Location: Downloaded boundaries are cached in tools::R_user_dir("situas", which = "data") and persist across R sessions.
# Create map files for Power BI and Leaflet
prepare_territorial_maps(
territorial_level = "comuni",
output_dir = "data"
)
# Create interactive Leaflet map
library(leaflet)
map_data <- readRDS("data/situas_map_comuni_61_20250101.rds")
map_territorial_units(map_data)get_situas_tables() - Download territorial data from SITUAS APIlist_available_reports() - Browse available SITUAS reportssearch_reports() - Search for specific reportsdownload_istat_boundaries() - Automatically download ISTAT boundary shapefileslist_istat_boundary_versions() - List available boundary versionscheck_boundary_updates() - Check for newer boundary versionsget_cached_boundaries_info() - View cached boundariesclean_boundary_cache() - Manage cached filesprepare_territorial_maps() - Create map-ready files (RDS, GeoJSON, TopoJSON)map_territorial_units() - Create interactive Leaflet mapsmap_territorial_choropleth() - Create choropleth maps with custom datasf_to_powerbi_topojson() - Export maps for Microsoft Power BIIf you use this package in your research, please cite it as:
Montaletti, G. (2025). situas: Client for the SITUAS API - Italian Territorial Codes and Classifications.
R package version 0.5.0. https://github.com/gmontaletti/situas
Giampaolo Montaletti Email: giampaolo.montaletti@gmail.com GitHub: https://github.com/gmontaletti ORCID: https://orcid.org/0009-0002-5327-1122