Skip to content

Commit

Permalink
Merge pull request #47 from CorrelAid/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
yannikbuhl authored Dec 6, 2024
2 parents ccc55c5 + bfe2e44 commit 9a0eb4c
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions R/gen_alternative_terms.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ gen_alternative_terms <- function(term = NULL,
database = c("all", "genesis", "zensus", "regio"),
verbose = TRUE,
...) {

caller <- as.character(match.call()[1])

gen_fun <- test_database_function(database,
Expand Down
6 changes: 3 additions & 3 deletions R/gen_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
gen_genesis_api <- function(endpoint,
...) {

url <- "https://www-genesis.destatis.de/genesisWS/rest/2020"
url <- Sys.getenv("RESTATIS_GENESIS_URL")

user_agent <- "https://github.com/CorrelAid/restatis"

Expand Down Expand Up @@ -69,7 +69,7 @@ gen_genesis_api <- function(endpoint,
gen_regio_api <- function(endpoint,
...) {

url <- "https://www.regionalstatistik.de/genesisws/rest/2020/"
url <- Sys.getenv("RESTATIS_REGIO_URL")

httr2::request(url) %>%
httr2::req_user_agent("https://github.com/CorrelAid/restatis") %>%
Expand Down Expand Up @@ -102,7 +102,7 @@ gen_regio_api <- function(endpoint,
gen_zensus_api <- function(endpoint,
...) {

url <- "https://ergebnisse.zensus2022.de/api/rest/2020"
url <- Sys.getenv("RESTATIS_ZENSUS_URL")

user_agent <- "https://github.com/CorrelAid/restatis"

Expand Down
1 change: 1 addition & 0 deletions R/gen_catalogue.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ gen_catalogue <- function(code = NULL,
error.ignore = FALSE,
verbose = TRUE,
...) {

caller <- as.character(match.call()[1])

gen_fun <- test_database_function(database,
Expand Down
1 change: 1 addition & 0 deletions R/gen_cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ gen_cube_ <- function(name,
classifyingkey3 = NULL,
stand = NULL,
language = Sys.getenv("GENESIS_LANG")) {

area <- match.arg(area)
database <- match.arg(database)

Expand Down
1 change: 1 addition & 0 deletions R/gen_find.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ gen_find <- function(term = NULL,
error.ignore = TRUE,
verbose = TRUE,
...) {

caller <- as.character(match.call()[1])

gen_fun <- test_database_function(database,
Expand Down
2 changes: 1 addition & 1 deletion R/gen_jobs.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ gen_list_jobs <- function(database = c("genesis", "regio"),
#' @param database Character string. Indicator if the GENESIS ('genesis') or regionalstatistik.de ('regio') database is called. Only one database can be addressed per function call. Default option is 'genesis'.
#' @param area Character string. Indicator from which area of the database the results are called. In general, 'all' is the appropriate solution. Default option is 'all'.
#' @param compress Boolean. Should empty rows and columns be discarded? Default is FALSE.
#' @param language Character string. Defines if the decimal mark and grouping mark of integers should be represented based on the European (e.g.: '100,5', '200.000,5') or American ('100.5', '200,000.5') system. Defaults to 'Sys.getenv("GENESIS_LANG")'.
#' @param language Character string. Defines if the decimal mark and grouping mark of integers should be represented based on the European (e.g.: '100,5', '200.000,5') or American ('100.5', '200,000.5') system. Defaults to 'Sys.getenv("RESTATIS_LANG")'.
#' @param all_character Boolean. Should all variables be imported as 'character' variables? Avoids fuzzy data type conversions if there are leading zeros or other special characters. Defaults to TRUE.
#'
#' @return Returns a data.frame with the table content
Expand Down
1 change: 1 addition & 0 deletions R/gen_objects2var.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ gen_objects2var <- function(code = NULL,
error.ignore = FALSE,
verbose = TRUE,
...) {

caller <- as.character(match.call()[1])

gen_fun <- test_database_function(database,
Expand Down
4 changes: 2 additions & 2 deletions R/utils_httr2.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ resp_check_data <- function(resp) {

if (!(httr2::resp_content_type(resp) %in% c("application/zip", "text/csv", "application/json"))) {

stop("Encountered an invalid response type.",
stop(paste0("Encountered an invalid response type (", httr2::resp_content_type(resp), ")."),
call. = FALSE)

}

return <- httr2::resp_content_type(resp)
return(httr2::resp_content_type(resp))

}

Expand Down
25 changes: 24 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
.onLoad <- function(libname, pkgname) {

# Set the functions whose results are to be cached
gen_genesis_api <<- memoise::memoise(gen_genesis_api)
gen_zensus_api <<- memoise::memoise(gen_zensus_api)
gen_regio_api <<- memoise::memoise(gen_regio_api)

if (!nzchar(Sys.getenv("GENESIS_LANG"))) Sys.setenv(GENESIS_LANG = "en")
# Set the default language of the package
if (!nzchar(Sys.getenv("GENESIS_LANG"))) Sys.setenv(RESTATIS_LANG = "en")

# Set the default URL for the GENESIS database
if (!nzchar(Sys.getenv("RESTATIS_GENESIS_URL"))) {

Sys.setenv(RESTATIS_GENESIS_URL = "https://www-genesis.destatis.de/genesisWS/rest/2020")

}

# Set the default URL for the www.regionalstatistik.de database
if (!nzchar(Sys.getenv("RESTATIS_REGIO_URL"))) {

Sys.setenv(RESTATIS_REGIO_URL = "https://www.regionalstatistik.de/genesisws/rest/2020/")

}

# Set the default URL for the ZENSUS 2022 database
if (!nzchar(Sys.getenv("RESTATIS_ZENSUS_URL"))) {

Sys.setenv(RESTATIS_ZENSUS_URL = "https://ergebnisse.zensus2022.de/api/rest/2020")

}

}

0 comments on commit 9a0eb4c

Please sign in to comment.