diff --git a/R/bfs_get_sse_data.R b/R/bfs_get_sse_data.R index f174f6f..138627b 100644 --- a/R/bfs_get_sse_data.R +++ b/R/bfs_get_sse_data.R @@ -122,7 +122,7 @@ bfs_get_sse_data <- # Get observation names instead of codes if specified if (variable_value_type == "text") { dim_df <- dim_df %>% - dplyr::mutate(dim_value = dplyr::coalesce(.data$valueTexts, .data$dim_value)) + dplyr::mutate(dim_value = dplyr::coalesce(.data$valueText, .data$dim_value)) } # Get dimension names instead of codes if specified diff --git a/R/bfs_get_sse_metadata.R b/R/bfs_get_sse_metadata.R index 8cf7226..3ffbab9 100644 --- a/R/bfs_get_sse_metadata.R +++ b/R/bfs_get_sse_metadata.R @@ -103,7 +103,7 @@ bfs_get_sse_metadata <- function(number_bfs, language = "de") { dplyr::left_join(dim_info, by = c("codelist_id" = "dimension_id")) %>% dplyr::left_join(all_codes, by = c("codelist_ref" = "codelist_id", "code")) %>% dplyr::select(code = "codelist_id", text = "codelist_text", - value = "code", valueTexts = "label", + value = "code", valueText = "label", position_dimension = "position") %>% dplyr::distinct() diff --git a/README.Rmd b/README.Rmd index cd9a768..dcd69e7 100644 --- a/README.Rmd +++ b/README.Rmd @@ -50,7 +50,7 @@ library(BFS) ## Access Swiss Stats Exporer API (NEW) -Two new functions are currently tested to access the new [Swiss Stats Explorer API](https://stats.swiss/). +Two new functions are currently tested to access the new [Swiss Stats Explorer API](https://stats.swiss/) (SSE). These functions are only accessible when using the development version of this package on GitHub. @@ -59,25 +59,37 @@ These functions are only accessible when using the development version of this p devtools::install_github("lgnbhl/BFS") ``` -Access a Swiss Stats Explorer dataset by BFS number using the new `bfs_get_sse_data()` function. +To get data from SSE you first create a query using the metadata codelist from SSE using the `bfs_get_sse_metadata()` function. First get the codelist of a BFS dataset: +```{r} +codelist <- bfs_get_sse_metadata("DF_LWZ_1", language = "en") + +codelist +``` + +Then filter the codelist to build your query: +```{r} +querydat <- codelist %>% + dplyr::filter((code == "GR_KT_GDE" & valueText %in% c("Aarau", "Olten")) | + (code == "WOHN_ANZAHL" & valueText == "Total") | + (code == "LEERWOHN_TYP" & valueText == "Vacant dwelling for rent") | + (code == "MEASURE_DIMENSION" & valueText == "Value")) +query <- tapply(querydat$value, querydat$code, c) + +query +``` + +This query can be used in the new `bfs_get_sse_data()` function to import the data. ```{r} bfs_get_sse_data( - number_bfs = "DF_PASTA_552_MONTHLY", + number_bfs = "DF_LWZ_1", language = "en", - query = list("FREQ" = "M", "ACCOMMODATION_TYPE" = c("552001"), - "COUNTRY_ORIGIN" = c("CH", "AUSL")), + query = query, start_period = "2020", end_period = "2023" ) ``` -You can also access the Swiss Stats Explorer metadata with the following function: - -```{r} -bfs_get_sse_metadata("DF_SSV_POL_LEG", language = "de") -``` - ### Get the data catalog Before downloading a BFS dataset, you need to get its related BFS number (FSO number) in the [official data catalog](https://www.bfs.admin.ch/bfs/en/home/statistics/catalogue.html). You can search in the catalog directly from R using the `bfs_get_catalog_data()` function in any language ("de", "fr", "it" or "en"): diff --git a/man/BFS-package.Rd b/man/BFS-package.Rd index f4cb455..02515a5 100644 --- a/man/BFS-package.Rd +++ b/man/BFS-package.Rd @@ -24,6 +24,7 @@ Useful links: Other contributors: \itemize{ + \item Marius Hodel (\href{https://orcid.org/0000-0001-8789-506X}{ORCID}) [contributor] \item Janosch Brenzel-Weiss [contributor] \item Joao Martins [contributor] \item Philipp Baumann \email{baumann-philipp@protonmail.com} (\href{https://orcid.org/0000-0002-3194-8975}{ORCID}) [contributor]