Download and import open Swiss economic time series from 'dataseries.org' < https://dataseries.org>, a comprehensive and up-to-date collection of public data from Switzerland. Series are retrieved through the public 'dataseries.org' API and imported as a 'data.frame' or 'ts' object.
Download and import open Swiss economic time series from
dataseries.org, a comprehensive and up-to-date
collection of public data from Switzerland. The package talks to the public
dataseries.org API and imports series as a
data.frame or ts object.
install.packages("dataseries")
Or the development version from GitHub:
# install.packages("remotes")
remotes::install_github("cynkra/dataseries")
A Python package with the same
interface is available: pip install dataseries.
Data on dataseries.org is organized into datasets. A dataset is a family of
related series and, in most cases, a multi-dimensional cube — a single time
series is one cell of that cube, addressed by the dataset plus one code per
dimension. For example the GDP dataset (ch_seco_gdp) splits along three
dimensions: type (nominal/real/…), structure (GDP, value added, …) and
seas_adj (seasonally adjusted or not).
ds_catalog() lists every dataset.ds_search(pattern) is a flat, searchable list of the individual series.ds_meta(id) describes a dataset's dimensions and the codes within them.ds(id, ...) downloads series.library(dataseries)
# Browse what's available
ds_catalog()
# Find a specific series across all datasets
ds_search("unemployment")
# A dataset's dimensions and codes
ds_meta("ch_seco_gdp")
# Whole dataset (long data.frame)
ds("ch_fso_cpi")
# One series: pass dimension codes as named arguments
ds("ch_fso_cpi", item = "100_100")
# Several series, restricted to a date range
ds("ch_fso_cpi", item = c("100_100", "100_1"), from = "2020-01-01")
# One cell of a multi-dimensional cube, as a ts object
ds("ch_seco_gdp", type = "real", structure = "gdp", seas_adj = "csa",
class = "ts")
All series on dataseries.org are regular (annual, quarterly or monthly), so
ts covers them. If you prefer xts, convert the ts in one line:
xts::as.xts(ds("ch_fso_cpi", item = "100_100", class = "ts")).
Dimension arguments are optional: omit them and you get the whole dataset.
Filtering happens on the server, so selecting one series does not download the
whole cube. Downloads are cached in memory for the session; cache_rm() forces
a fresh download.
The catalog and search index are translated. Pass lang to get titles and
labels in any Swiss national language (English is used where a translation is
missing):
ds_catalog(lang = "de")
ds_search("arbeitslosen", lang = "de")
Searching matches the labels in the chosen language, so you can look for German terms directly.
In Python, use the dataseries package, which mirrors this interface and returns pandas DataFrames.
Every series is also available as a plain CSV from any tool that can read a URL:
https://api.dataseries.org/series.csv?dataset=ch_fso_cpi&dims=item=100_100