pixieweb is an R client for PX-Web statistical APIs. It provides a pipe-friendly, tibble-based interface for discovering, inspecting and downloading data from national statistics agencies — including SCB (Sweden), SSB (Norway), Statistics Finland, and more.
To learn more about using pixieweb, it is recommended you use the following resources in order:
pixieweb is open source licensed under the Affero Gnu Public License version 3. This means you are free to download the source, modify and redistribute it as you please, but any copies or modifications must retain the original license. Please see the file LICENSE.md for further information.
Note on pxweb: The excellent pxweb package by rOpenGov already provides comprehensive R access to PX-Web APIs. pixieweb is not a replacement — it offers an alternative paradigm built around search-then-fetch discovery and progressive disclosure. If you already use pxweb and it works for you, there is no need to switch. Choose the workflow that fits your needs.
pixieweb is on CRAN. To install it, run the following code in R:
install.packages("pixieweb")
To install the latest development version from GitHub, use the remotes package:
library("remotes")
# remotes::install_github("LCHansson/pixieweb")
install.packages("pixieweb", repos = c('https://lchansson.r-universe.dev', 'https://cloud.r-project.org'))
library(pixieweb)
# Connect to Statistics Sweden
scb <- px_api("scb", lang = "en")
# Search for tables about population
tables <- get_tables(scb, query = "population")
# Inspect variables in a table
vars <- get_variables(scb, tables$id[1])
# Download data. Every variable with `elimination = FALSE` in `vars` must be
# given a selection; the rest are aggregated away by the API.
data <- get_data(scb, tables$id[1],
ContentsCode = "*",
Tid = px_top(5)
)
px_all(), px_top(), px_bottom(), px_from(), px_to(), px_range() for concise variable selectionspixieweb_cache_dir()
For multi-user web applications or workflows that benefit from a shared,
persistent cache, pixieweb integrates with the
nordstatExtras package.
When installed, get_data(), get_tables(), table_enrich(), and
other functions can write to a shared SQLite file instead of per-session
.rds files:
# install.packages("devtools")
devtools::install_github("LCHansson/nordstatExtras")
library(nordstatExtras)
handle <- nxt_open("cache.sqlite")
scb <- px_api("scb")
# Metadata and data cached in the same SQLite file
tables <- get_tables(scb, cache = TRUE, cache_location = handle)
data <- get_data(scb, "TAB638",
Region = c("0180", "1480"),
ContentsCode = "*",
Tid = px_top(5),
cache = TRUE, cache_location = handle
)
# table_enrich with per-table caching + async support
enriched <- table_enrich(tables, cache = TRUE,
cache_location = handle)
nxt_close(handle)
Features include cell-level deduplication across overlapping queries,
per-table incremental enrichment with resume-on-crash, async background
fetching via mirai, and FTS5-powered typeahead search via
nxt_search(). See the
nordstatExtras README
for details.
You are welcome to contribute to the further development of the pixieweb package in any of the following ways:
pixieweb is part of a family of R packages for Swedish and Nordic open statistics that share the same design philosophy — tibble-based, pipe-friendly, and offline-safe:
See also pxweb — the original and established PX-Web client for R, by rOpenGov.
Please note that the pixieweb project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
AGPL (>= 3)