Learn R Programming

dataseries (version 1.0.0)

ds: Download time series from dataseries.org

Description

ds() downloads open Swiss economic time series from dataseries.org.

Usage

ds(dataset, ..., from = NULL, to = NULL, class = c("data.frame", "ts"))

Value

A data.frame or ts/mts object, or NULL if the selection is empty.

Arguments

dataset

a single dataset id, as listed by ds_catalog().

...

dimension filters, given as named arguments where each name is a dimension of dataset and each value is one or more codes, e.g. type = "real" or structure = c("gdp", "gva"). A single named list may be passed instead, which is convenient programmatically (e.g. from the output of ds_search()). See ds_meta() for the available dimensions and codes.

from, to

optional date bounds (a Date or an ISO "YYYY-MM-DD" string) that restrict the returned range, inclusive.

class

class of the return value: "data.frame" (the default, one row per observation in long format) or "ts". For "ts" the selected series are laid out as columns, one per cell. (To obtain an xts object, wrap the result: xts::as.xts(ds(..., class = "ts")).)

Details

Data on dataseries.org is organized into datasets. A dataset is a family of related series and is, in most cases, a multi-dimensional cube: a single time series is one cell of the cube, addressed by the dataset plus one code per dimension. Pass those codes as named arguments (the names are the dimension names, see ds_meta()):

ds("ch_seco_gdp", type = "real", structure = "gdp", seas_adj = "csa")

Dimension arguments are optional. Omit them and you get the whole dataset (all series, in long format). A few datasets are a single series and take no dimensions at all (e.g. ds("ch_kof_barometer")). Filtering happens on the server, so selecting one series does not download the whole cube.

Downloads are cached in memory for the session. Run cache_rm() to force a fresh download.

See Also

ds_catalog() for the list of datasets and ds_meta() for a dataset's dimensions.

Examples

Run this code
if (FALSE) {
# whole dataset (long data.frame)
ds("ch_fso_cpi")

# one series, by dimension code
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")

# as a ts object
ds("ch_seco_gdp", type = "real", structure = "gdp", seas_adj = "csa",
   class = "ts")
}

Run the code above in your browser using DataLab