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.

Caching and path gestion will be improved in the next BFS package release (for now only available on Github) using the pins R package. You can try the BFS development version by installing it from Github.

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.


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)


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])


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 exist. You should then use the “STAT-TAB - interactive table” service provided by BFS to download manually the dataset.

To open the folder containing the downloaded BFS dataset (only available in the development version on Github for now), you can simply use the bfs_open_dir() function.

Other information

Alternative R package: pxweb

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