BFS

Introduction

The BFS R package allows the user to search and download public data from the Swiss Federal Statistical Office (BFS) in a dynamic and reproducible way.

Usage Example

To search and download data from the BFS, you first need to retrieve information about the available datasets. The bfs_get_metadata() function returns a data frame/tibble containing the titles, publication dates, observation periods, website urls and download urls of all available BFS datasets of a given language: German (“de”, by default), French (“fr”), Italian (“it”) or English (“en”). Note that Italian and English languages give access to less datasets.

library(BFS)

meta_en <- bfs_get_metadata(language = "en")

To search for a dataset, you can use the bfs_search() function.

meta_en_edu <- bfs_search("education", data = meta_en)

print(meta_en_edu)

To download a BFS dataset, add the related url link from the url_px column of the downloaded metadata as an argument to the bfs_get_dataset() function.

df_edu <- bfs_get_dataset(meta_en_edu$url_px[3])

print(df_edu)

In case the url_px link to download the PC-Axis file is broken, you can have a look at its related BFS webpage using the url link.

browseURL(meta_en_edu$url[3]) # open webpage

Sometimes the PC-Axis file of the dataset doesn’t exists. You should then use the “STAT-TAB - interactive table” service provided by BFS to download manually the dataset.

Other information

Alternative R package: pxweb

This package is in no way officially related to or endorsed by the Swiss Federal Statistical Office (BFS).