From 8f84c57661fdd4b6a285ec5ec95014e534b0dffa Mon Sep 17 00:00:00 2001 From: buhly Date: Tue, 17 Dec 2024 21:35:37 +0100 Subject: [PATCH] work on intro of gen_api and intro of pagelength --- R/gen_alternative_terms.R | 32 +++++++++--------- R/gen_catalogue.R | 3 ++ R/gen_jobs.R | 15 ++++----- R/gen_modified_data.R | 3 ++ R/gen_objects2stat.R | 3 ++ R/gen_objects2var.R | 69 ++++++++++++++++++++------------------- R/gen_qualitysigns.R | 18 +++++----- R/gen_var2-val2.R | 8 ++--- restatis.Rproj | 1 + 9 files changed, 83 insertions(+), 69 deletions(-) diff --git a/R/gen_alternative_terms.R b/R/gen_alternative_terms.R index 0b14964..77513a6 100644 --- a/R/gen_alternative_terms.R +++ b/R/gen_alternative_terms.R @@ -5,6 +5,7 @@ #' @param term Character string. Maximum length of 15 characters. Term or word for which you are searching for alternative or related terms. Use of '*' as a placeholder is possible to generate broader search areas. #' @param similarity Boolean. Indicator if the output of the function should be sorted based on a Levenshtein edit distance based on the \code{adist()} function. Default is 'TRUE'. #' @param database Character string. Indicator if the GENESIS ('genesis'), Zensus 2022 ('zensus') or regionalstatistik.de ('regio') database is called. Default option is 'all'. +#' @param pagelength Integer. Maximum length of results or objects (e.g., number of tables). Defaults to 500. #' @param verbose Boolean. Indicator if the output of the function should include detailed messages and warnings. Default option is 'TRUE'. Set the parameter to 'FALSE' to suppress additional messages and warnings. #' @param ... Additional parameters for the API call. These parameters are only affecting the call itself, no further processing. For more details see `vignette("additional_parameter")`. #' @@ -27,49 +28,50 @@ gen_alternative_terms <- function(term = NULL, similarity = TRUE, database = c("all", "genesis", "zensus", "regio"), + pagelength = 500, verbose = TRUE, ...) { caller <- as.character(match.call()[1]) - gen_fun <- test_database_function(database, - error.input = TRUE, - text = verbose) + database_vector <- test_database_function(database, + error.input = TRUE, + text = verbose) check_function_input(term = term, similarity = similarity, + pagelength = pagelength, caller = caller, verbose = verbose) #----------------------------------------------------------------------------- - res <- lapply(gen_fun, function(db){ + res <- lapply(database_vector, function(db){ if (verbose) { - info <- paste("Started the processing of", rev_database_function(db), "database.") + info <- paste("Started the processing of", db, "database.") message(info) } - par_list <- list(endpoint = "catalogue/terms", - username = gen_auth_get(database = rev_database_function(db))$username, - password = gen_auth_get(database = rev_database_function(db))$password, - selection = term, - ...) - - results_raw <- do.call(db, par_list) + results_raw <- gen_api(endpoint = "catalogue/terms", + database = db, + username = gen_auth_get(database = db)$username, + password = gen_auth_get(database = db)$password, + selection = term, + ...) #--------------------------------------------------------------------------- results_json <- test_if_json(results_raw) - if (length(results_json$List) == 0 & length(gen_fun) == 1) { + if (length(results_json$List) == 0 & length(database_vector) == 1) { stop("No related terms found for your code.", call. = FALSE) - } else if (length(results_json$List) == 0 & length(gen_fun) > 1) { + } else if (length(results_json$List) == 0 & length(database_vector) > 1) { termslist <- "No related terms found for your code." @@ -115,7 +117,7 @@ gen_alternative_terms <- function(term = NULL, } attr(list_resp, "Term") <- term - attr(list_resp, "Database") <- rev_database_function(db) + attr(list_resp, "Database") <- db attr(list_resp, "Language") <- results_json$Parameter$language attr(list_resp, "Pagelength") <- results_json$Parameter$pagelength attr(list_resp, "Copyright") <- results_json$Copyright diff --git a/R/gen_catalogue.R b/R/gen_catalogue.R index 606cec1..ecc5fcf 100644 --- a/R/gen_catalogue.R +++ b/R/gen_catalogue.R @@ -8,6 +8,7 @@ #' @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'. Not used for 'statistics'. #' @param detailed Boolean. Indicator if the function should return the detailed output of the iteration including all object-related information or only a shortened output including only code and object title. Default option is 'FALSE'. #' @param sortcriterion Character string. Indicator if the output should be sorted by 'code' or 'content'. This is a parameter of the API call itself. The default is 'code'. +#' @param pagelength Integer. Maximum length of results or objects (e.g., number of tables). Defaults to 500. #' @param error.ignore Boolean. Indicator if the function should stop if an error occurs or no object for the request is found or if it should produce a token as response. Default option is 'FALSE'. #' @param verbose Boolean. Indicator if the output of the function should include detailed messages and warnings. Default option is 'TRUE'. Set the parameter to 'FALSE' to suppress additional messages and warnings. #' @param ... Additional parameters for the API call. These parameters are only affecting the call itself, no further processing. For more details see `vignette("additional_parameter")`. @@ -33,6 +34,7 @@ gen_catalogue <- function(code = NULL, area = c("all", "public", "user"), detailed = FALSE, sortcriterion = c("code", "content"), + pagelength = 500, error.ignore = FALSE, verbose = TRUE, ...) { @@ -50,6 +52,7 @@ gen_catalogue <- function(code = NULL, error.ignore = error.ignore, database = database_vector, sortcriterion = sortcriterion, + pagelength = pagelength, caller = caller, verbose = verbose) diff --git a/R/gen_jobs.R b/R/gen_jobs.R index 89153c7..4366b06 100644 --- a/R/gen_jobs.R +++ b/R/gen_jobs.R @@ -20,9 +20,10 @@ gen_list_jobs <- function(database = c("genesis", "regio"), flat = FALSE, ...) { - gen_fun <- test_database_function(database, - error.input = TRUE, - text = TRUE) + # database_vector will hold a vector of the specified databases to query + database_vector <- test_database_function(database, + error.input = error.ignore, + text = verbose) if (length(database) != 1) { @@ -49,11 +50,9 @@ gen_list_jobs <- function(database = c("genesis", "regio"), #----------------------------------------------------------------------------- - par_list <- list(endpoint = "catalogue/jobs", - sortcriterion = sortcriterion, - ...) - - results_raw <- do.call(gen_fun, par_list) + results_raw <- gen_api(endpoint = "catalogue/jobs", + sortcriterion = sortcriterion, + ...) results_json <- test_if_json(results_raw) diff --git a/R/gen_modified_data.R b/R/gen_modified_data.R index da66652..807bf10 100644 --- a/R/gen_modified_data.R +++ b/R/gen_modified_data.R @@ -6,6 +6,7 @@ #' @param database Character string. Indicator if the GENESIS ('genesis'), Zensus 2022 ('zensus') or regionalstatistik.de ('regio') database is called. Default option is 'all'. #' @param type Character string. Specific GENESIS and regionalstatistik.de object types: 'tables', 'statistics', and 'statisticsUpdates'. Specific Zensus 2022 object types: 'tables' and 'statistics'. All types that are specific for one database can be used together through 'all', which is the default. #' @param date Character string. Specific date that is used as the last update or upload time to include an object in return. Default option is 'now', which uses the current date of your system. Alternative options are 'week_before', using the current date of your system minus 7 days, 'month_before', using the current date of your system minus 4 weeks, and 'year_before', using the current date of your system minus 52 weeks. Additionally, it is possible to fill in a specific date of format 'DD.MM.YYYY'. +#' @param pagelength Integer. Maximum length of results or objects (e.g., number of tables). Defaults to 500. #' @param verbose Boolean. Indicator if the output of the function should include detailed messages and warnings. Default option is 'TRUE'. Set the parameter to 'FALSE' to suppress additional messages and warnings. #' @param ... Additional parameters for the API call. These parameters are only affecting the call itself, no further processing. For more details see `vignette("additional_parameter")`. #' @@ -29,6 +30,7 @@ gen_modified_data <- function(code = "", database = c("all", "genesis", "zensus", "regio"), type = c("all", "tables", "statistics", "statisticsUpdates"), date = c("now", "week_before", "month_before", "year_before"), + pagelength = 500, verbose = TRUE, ...) { @@ -42,6 +44,7 @@ gen_modified_data <- function(code = "", date <- check_function_input(code = code, type = type, date = date, + pagelength = pagelength, database = database_vector, verbose = verbose) diff --git a/R/gen_objects2stat.R b/R/gen_objects2stat.R index 0d60ccd..8fae7b4 100644 --- a/R/gen_objects2stat.R +++ b/R/gen_objects2stat.R @@ -8,6 +8,7 @@ #' @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'. Not used for 'statistics'. #' @param detailed Boolean. Indicator if the function should return the detailed output of the iteration including all object-related information or only a shortened output including only code and object title. Default option is 'FALSE'. #' @param sortcriterion Character string. Indicator if the output should be sorted by 'code' or 'content'. This is a parameter of the API call itself. The default is 'code'. +#' @param pagelength Integer. Maximum length of results or objects (e.g., number of tables). Defaults to 500. #' @param error.ignore Boolean. Indicator if the function should stop if an error occurs or no object for the request is found or if it should produce a token as response. Default option is 'FALSE'. #' @param verbose Boolean. Indicator if the output of the function should include detailed messages and warnings. Default option is 'TRUE'. Set the parameter to 'FALSE' to suppress additional messages and warnings. #' @param ... Additional parameters for the API call. These parameters are only affecting the call itself, no further processing. For more details see `vignette("additional_parameter")`. @@ -32,6 +33,7 @@ gen_objects2stat <- function(code = NULL, area = c("all", "public", "user"), detailed = FALSE, sortcriterion = c("code", "content"), + pagelength = 500, error.ignore = FALSE, verbose = TRUE, ...) { @@ -48,6 +50,7 @@ gen_objects2stat <- function(code = NULL, detailed = detailed, error.ignore = error.ignore, database = database_vector, + pagelength = pagelength, sortcriterion = sortcriterion, caller = caller, verbose = verbose) diff --git a/R/gen_objects2var.R b/R/gen_objects2var.R index 14b29b5..fbaef35 100644 --- a/R/gen_objects2var.R +++ b/R/gen_objects2var.R @@ -8,6 +8,7 @@ #' @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'. Not used for 'statistics'. #' @param detailed Boolean. Indicator if the function should return the detailed output of the iteration including all object-related information or only a shortened output including only code and object title. Default option is 'FALSE'. #' @param sortcriterion Character string. Indicator if the output should be sorted by 'code' or 'content'. This is a parameter of the API call itself. The default is 'code'. +#' @param pagelength Integer. Maximum length of results or objects (e.g., number of tables). Defaults to 500. #' @param error.ignore Boolean. Indicator if the function should stop if an error occurs or no object for the request is found or if it should produce a token as response. Default option is 'FALSE'. #' @param verbose Boolean. Indicator if the output of the function should include detailed messages and warnings. Default option is 'TRUE'. Set the parameter to 'FALSE' to suppress additional messages and warnings. #' @param ... Additional parameters for the API call. These parameters are only affecting the call itself, no further processing. For more details see `vignette("additional_parameter")`. @@ -32,21 +33,24 @@ gen_objects2var <- function(code = NULL, area = c("all", "public", "user"), detailed = FALSE, sortcriterion = c("code", "content"), + pagelength = 500, error.ignore = FALSE, verbose = TRUE, ...) { caller <- as.character(match.call()[1]) - gen_fun <- test_database_function(database, - error.input = error.ignore, - text = verbose) + # database_vector will hold a vector of the specified databases to query + database_vector <- test_database_function(database, + error.input = error.ignore, + text = verbose) check_function_input(code = code, category = category, detailed = detailed, error.ignore = error.ignore, - database = gen_fun, + pagelength = pagelength, + database = database_vector, sortcriterion = sortcriterion, caller = caller, verbose = verbose) @@ -59,11 +63,11 @@ gen_objects2var <- function(code = NULL, #----------------------------------------------------------------------------- - res <- lapply(gen_fun, function(db){ + res <- lapply(database_vector, function(db){ if (isTRUE(verbose)) { - info <- paste("Started the processing of", rev_database_function(db), "database.") + info <- paste("Started the processing of", db, "database.") message(info) @@ -73,15 +77,14 @@ gen_objects2var <- function(code = NULL, if ("tables" %in% category) { - par_list <- list(endpoint = "catalogue/tables2variable", - username = gen_auth_get(database = rev_database_function(db))$username, - password = gen_auth_get(database = rev_database_function(db))$password, - name = code, - area = area, - sortcriterion = sortcriterion, - ...) - - results_raw <- do.call(db, par_list) + results_raw <- gen_api(endpoint = "catalogue/tables2variable", + database = db, + username = gen_auth_get(database = db)$username, + password = gen_auth_get(database = db)$password, + name = code, + area = area, + sortcriterion = sortcriterion, + ...) results_json <- test_if_json(results_raw) @@ -124,15 +127,14 @@ gen_objects2var <- function(code = NULL, if ("statistics" %in% category) { - par_list <- list(endpoint = "catalogue/statistics2variable", - username = gen_auth_get(database = rev_database_function(db))$username, - password = gen_auth_get(database = rev_database_function(db))$password, - name = code, - area = area, - sortcriterion = sortcriterion, - ...) - - results_raw <- do.call(db, par_list) + results_raw <- gen_api(endpoint = "catalogue/statistics2variable", + database = db, + username = gen_auth_get(database = db)$username, + password = gen_auth_get(database = db)$password, + name = code, + area = area, + sortcriterion = sortcriterion, + ...) results_json <- test_if_json(results_raw) @@ -178,15 +180,16 @@ gen_objects2var <- function(code = NULL, df_cubes <- "There are generally no 'cubes' objects available for the 'zensus' database." - } else if ("cubes" %in% category && (db == "gen_genesis_api" || db == "gen_regio_api")) { + } else if ("cubes" %in% category && (db == "genesis" || db == "regio")) { - results_raw <- do.call(db, list(endpoint = "catalogue/timeseries2variable", - username = gen_auth_get(database = rev_database_function(db))$username, - password = gen_auth_get(database = rev_database_function(db))$password, - name = code, - area = area, - sortcriterion = sortcriterion, - ...)) + results_raw <- gen_api(endpoint = "catalogue/timeseries2variable", + database = db, + username = gen_auth_get(database = db)$username, + password = gen_auth_get(database = db)$password, + name = code, + area = area, + sortcriterion = sortcriterion, + ...) results_json <- test_if_json(results_raw) @@ -252,7 +255,7 @@ gen_objects2var <- function(code = NULL, } attr(list_resp, "Code") <- results_json$Parameter$term - attr(list_resp, "Database") <- rev_database_function(db) + attr(list_resp, "Database") <- db attr(list_resp, "Category") <- category attr(list_resp, "Language") <- results_json$Parameter$language attr(list_resp, "Pagelength") <- results_json$Parameter$pagelength diff --git a/R/gen_qualitysigns.R b/R/gen_qualitysigns.R index 346df2a..eadfd50 100644 --- a/R/gen_qualitysigns.R +++ b/R/gen_qualitysigns.R @@ -11,16 +11,16 @@ gen_signs <- function(database = c("all", "genesis", "zensus", "regio"), ...) { - gen_fun <- test_database_function(database, - error.input = TRUE, - text = TRUE) + # database_vector will hold a vector of the specified databases to query + database_vector <- test_database_function(database, + error.input = error.ignore, + text = verbose) - res <- lapply(gen_fun, function(db){ + res <- lapply(database_vector, function(db){ - par_list <- list(endpoint = "catalogue/qualitysigns", - ...) - - results_raw <- do.call(db, par_list) + results_raw <- gen_api(endpoint = "catalogue/qualitysigns", + database = db, + ...) results_json <- test_if_json(results_raw) @@ -28,7 +28,7 @@ gen_signs <- function(database = c("all", "genesis", "zensus", "regio"), characteristics = c("Code", "Content")))) - attr(mid_res, "Database") <- rev_database_function(db) + attr(mid_res, "Database") <- db attr(mid_res, "Language") <- results_json$Parameter$language attr(mid_res, "Copyright") <- results_json$Copyright diff --git a/R/gen_var2-val2.R b/R/gen_var2-val2.R index b8af8a3..62b43c2 100644 --- a/R/gen_var2-val2.R +++ b/R/gen_var2-val2.R @@ -7,7 +7,7 @@ #' @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'. Not used for 'statistics'. #' @param detailed Boolean. Indicator if the function should return the detailed output of the iteration including all object-related information or only a shortened output including only code and object title. Default option is 'FALSE'. #' @param sortcriterion Character string. Indicator if the output should be sorted by 'code' or 'content'. This is a parameter of the API call itself. The default is 'code'. -#' @param pagelength Integer. Maximum length of results (e.g., number of tables). Defaults to 500. +#' @param pagelength Integer. Maximum length of results or objects (e.g., number of tables). Defaults to 500. #' @param error.ignore Boolean. Indicator if the function should stop if an error occurs or no object for the request is found or if it should produce a token as response. Default option is 'FALSE'. #' @param verbose Boolean. Indicator if the output of the function should include detailed messages and warnings. Default option is 'TRUE'. Set the parameter to 'FALSE' to suppress additional messages and warnings. #' @param ... Additional parameters for the API call. These parameters are only affecting the call itself, no further processing. For more details see `vignette("additional_parameter")`. @@ -159,7 +159,7 @@ gen_var2stat <- function(code = NULL, #' @param database Character string. Indicator if the GENESIS ('genesis'), Zensus 2022 ('zensus') or regionalstatistik.de ('regio') database is called. Default option is 'all'. #' @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'. Not used for 'statistics'. #' @param sortcriterion Character string. Indicator if the output should be sorted by 'code' or 'content'. This is a parameter of the API call itself. The default is 'code'. -#' @param pagelength Integer. Maximum length of results (e.g., number of tables). Defaults to 500. +#' @param pagelength Integer. Maximum length of results or objects (e.g., number of tables). Defaults to 500. #' @param error.ignore Boolean. Indicator for values if the function should stop if an error occurs or no object for the request is found or if it should produce a token as response. Default option is 'TRUE', this prevents the function to stop even if a variable has no further explanation (often the case for numerical variables). #' @param verbose Boolean. Indicator if the output of the function should include detailed messages and warnings. Default option is 'TRUE'. Set the parameter to 'FALSE' to suppress additional messages and warnings. #' @param ... Additional parameters for the API call. These parameters are only affecting the call itself, no further processing. For more details see `vignette("additional_parameter")`. @@ -304,7 +304,7 @@ gen_val2var <- function(code = NULL, #' @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'. Not used for 'statistics'. #' @param detailed Boolean. Indicator if the function should return the detailed output of the iteration including all object-related information or only a shortened output including only code and object title. Default option is 'FALSE'. #' @param sortcriterion Character string. Indicator if the output should be sorted by 'code' or 'content'. This is a parameter of the API call itself. The default is 'code'. -#' @param pagelength Integer. Maximum length of results (e.g., number of tables). Defaults to 500. +#' @param pagelength Integer. Maximum length of results or objects (e.g., number of tables). Defaults to 500. #' @param error.ignore.var Boolean. Indicator for variables if the function should stop if an error occurs or no object for the request is found or if it should produce a token as response. Default option is 'FALSE'. #' @param error.ignore.val Boolean. Indicator for values if the function should stop if an error occurs or no object for the request is found or if it should produce a token as response. Default option is 'TRUE', this prevents the function to stop even if a variable has no further explanation (often the case for numerical variables). #' @param verbose Boolean. Indicator if the output of the function should include detailed messages and warnings. Default option is 'TRUE'. Set the parameter to 'FALSE' to suppress additional messages and warnings. @@ -417,7 +417,7 @@ gen_val2var2stat <- function(code = NULL, #' @param database Character string. Indicator if the GENESIS ('genesis'), Zensus 2022 ('zensus') or regionalstatistik.de ('regio') database is called. Default option is 'all'. #' @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'. Not used for 'statistics'. #' @param sortcriterion Character string. Indicator if the output should be sorted by 'code' or 'content'. This is a parameter of the API call itself. The default is 'code'. -#' @param pagelength Integer. Maximum length of results (e.g., number of tables). Defaults to 500. +#' @param pagelength Integer. Maximum length of results or objects (e.g., number of tables). Defaults to 500. #' @param error.ignore Boolean. Indicator if the function should stop if an error occurs or no object for the request is found or if it should produce a token as response. Default option is 'FALSE'. #' @param verbose Boolean. Indicator if the output of the function should include detailed messages and warnings. Default option is 'TRUE'. Set the parameter to 'FALSE' to suppress additional messages and warnings. #' @param ... Additional parameters for the API call. These parameters are only affecting the call itself, no further processing. For more details see `vignette("additional_parameter")`. diff --git a/restatis.Rproj b/restatis.Rproj index 69fafd4..7ceb7ed 100644 --- a/restatis.Rproj +++ b/restatis.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: 4b848548-d67f-483d-919f-2d71259e2bc2 RestoreWorkspace: No SaveWorkspace: No