ssbtools is a lightweight R package that simplifies retrieving, caching, and reusing data from Statistics Norway (SSB)'s JSON-stat API.
It is especially useful when working with saved queries from SSB's StatBank and when you want to avoid re-downloading large datasets unnecessarily.
# Install devtools if you haven't already
install.packages("devtools")
# Install ssbtools from GitHub
devtools::install_github("willemdig/ssbtools")- Save your query as a
.jsonfile from SSB StatBank. (Alternatively, if you know the data table, you can get queries from https://data.ssb.no/api/v0/no/console) - Place the file inside a
JSON/folder in your project directory. - Use this naming format for the file:
JSON/ssbapi_table_<table_id>.json
Example directory structure:
your-project/
├── JSON/
│ └── ssbapi_table_12030.json
- In your R script:
library(ssbtools)
df <- ssb_get_csv("12030")This will:
- Load the query from
JSON/ssbapi_table_12030.json - Download fresh data from SSB (only if the content has changed)
- Save or reuse the result at
csv/ssb/ssb_table_12030.csv
Retrieves data from SSB using a saved JSON query file, and caches the result as a CSV. Uses hashing to avoid redundant downloads.
Fetches metadata (dimensions and values) for a given SSB table. Useful for understanding the structure before building a query.
Builds a complete query using all values for all variables in the table and retrieves the entire dataset.
The first time you run ssb_get_csv(), the dataset is fetched from SSB and saved locally.
On later runs, the content is compared using a hash and only updated if it has changed.
ssb_get_full_table() doesn't have this functionality yet, but I'll get back to it.
This package is licensed under the MIT License and provided without warranty.
It was developed independently using open data from Statistics Norway (SSB).