This package distributes demand and train service data from the São Paulo metro system inside R. The data covers 2012 to 2026 and comes from several operators. Most of it is already public, but it is scattered across poorly structured CSV and PDF files.
METRÔ publishes lines 1, 2, 3, 15, and line 5 through July 2018 on its open data portal. Line 4, and line 5 from August 2018 onward, come from the Insper Dataverse.
All datasets are bundled with the package, so they load without a
download. Demand, service, and calendar data are tibbles; routes and
stations are sf objects, and metro_colors is a named vector.
The package covers every metro line in São Paulo. Commuter train (CPTM) demand is not included, though train lines and stations do appear in the spatial datasets.
| Line | Name | Operator | Coverage |
|---|---|---|---|
| 1 | Azul (Blue) | METRÔ | Jan 2016 – Jul 2026 |
| 2 | Verde (Green) | METRÔ | Jan 2016 – Jul 2026 |
| 3 | Vermelha (Red) | METRÔ | Jan 2016 – Jul 2026 |
| 4 | Amarela (Yellow) | ViaQuatro | Jan 2012 – Mar 2026 |
| 5 | Lilás (Lilac) | METRÔ / ViaMobilidade | Jan 2016 – Apr 2026 |
| 15 | Prata (Silver) | METRÔ | Jan 2016 – Jul 2026 |
Coverage refers to line_entries_monthly, which is missing July 2017
for every METRO-sourced line. The other datasets start later for some
lines. The Metro Demand
Data
article gives the coverage window of every dataset by line.
Install the released version from CRAN.
install.packages("metrosp")The development version is on R-universe.
install.packages('metrosp', repos = c('https://viniciusoike.r-universe.dev', 'https://cloud.r-project.org'))Four datasets carry the demand data: line_entries_monthly,
line_transported_monthly, station_transported_monthly, and
station_entries_daily. line_service_monthly reports train service;
the remaining datasets support analysis and visualization.
| Dataset | Description | Frequency | Spatial |
|---|---|---|---|
line_entries_monthly |
Monthly passenger entries by line and day-type metric | Monthly | No |
line_transported_monthly |
Monthly passengers transported by line | Monthly | No |
station_transported_monthly |
Average weekday passengers transported by station | Monthly | No |
station_entries_daily |
Daily passenger entries by station | Daily | No |
line_service_monthly |
Minimum interval between trains and commercial speed by line | Monthly | No |
calendar_spo |
São Paulo holiday and business-day calendar | Daily | No |
metro_colors |
Named vector of official metro line colors | — | No |
rail_lines |
Metro and train line routes (current + planned) | — | Yes |
rail_stations |
Metro and train station locations (current + planned) | — | Yes |
Every demand dataset counts individual passengers. The data dictionary defines every column, and the Metro Demand Data article covers coverage windows, source defects, and the conventions behind the numbers.
The bundled demand data is a fixed snapshot, current through July 2026; bundled service data reaches August 2026. The snapshot changes when the column schema changes or a release deliberately carries new data, not on routine monthly refreshes. METRÔ publishes on an irregular schedule and revises past years, so these numbers drift from the source over time.
read_metro_demand() reads newer demand data. Every pipeline run
publishes a fresh build of the four demand datasets and
line_service_monthly to the rolling data-latest
release, plus a dated
tag for that month. A later run in the same month replaces the dated
batch, so monthly vintages are revisable.
library(metrosp)
# Latest published data
entrance <- read_metro_demand("line_entries_monthly")
# A monthly batch, so an analysis can name the vintage it used
entrance_sep <- read_metro_demand("line_entries_monthly", vintage = "2026-09")read_metro_service() does the same for line_service_monthly.
# Minimum train interval and commercial speed by line
service <- read_metro_service(source = "bundled")Downloads use the platform-specific user cache returned by
tools::R_user_dir(). Use metrosp_cache() to inspect it,
metrosp_cache_clear() to remove files, or cache = FALSE to keep a
download only for the current session. Columns match the bundled
datasets, so the same code works with either.
The data is bundled with the package, meaning it works out of the box and doesn’t rely on internet connection. To use a dataset simply call its name.
library(metrosp)
# To work with spatial datasets (rail lines and stations)
library(sf)
# Passenger entries by line
line_entries_monthly
# Station-level weekday averages
station_transported_monthly
# Minimum train interval and commercial speed by line
line_service_monthly
# Spatial line routes
rail_linesAn interactive dashboard for browsing and downloading these datasets lives in a separate repository: metrosp-explorer.
- METRÔ: Companhia do Metropolitano de São Paulo (METRO), demand and train service.
- Lines 4/5 data: Insper Dataverse (ViaQuatro / ViaMobilidade).
- Spatial data: GeoSampa, Prefeitura de São Paulo.
This package is still in development. While the datasets are stable and checked on every new release, there may still be errors. If you find any, please open an issue.
