Skip to content

Commit

Permalink
work on intro of gen_api and intro of pagelength
Browse files Browse the repository at this point in the history
  • Loading branch information
yannikbuhl committed Dec 17, 2024
1 parent 77d9b1d commit 8f84c57
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 69 deletions.
32 changes: 17 additions & 15 deletions R/gen_alternative_terms.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")`.
#'
Expand All @@ -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."

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions R/gen_catalogue.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")`.
Expand All @@ -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,
...) {
Expand All @@ -50,6 +52,7 @@ gen_catalogue <- function(code = NULL,
error.ignore = error.ignore,
database = database_vector,
sortcriterion = sortcriterion,
pagelength = pagelength,
caller = caller,
verbose = verbose)

Expand Down
15 changes: 7 additions & 8 deletions R/gen_jobs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions R/gen_modified_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")`.
#'
Expand All @@ -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,
...) {

Expand All @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions R/gen_objects2stat.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")`.
Expand All @@ -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,
...) {
Expand All @@ -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)
Expand Down
69 changes: 36 additions & 33 deletions R/gen_objects2var.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")`.
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions R/gen_qualitysigns.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
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)

mid_res <- list("Output" = tibble::as_tibble(binding_lapply(results_json$List,
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

Expand Down
Loading

0 comments on commit 8f84c57

Please sign in to comment.