We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Urzustand:
json_create_lite <- function(variable, varlabel, startyear, endyear, tabletype, exportpath, dataset) { if (dataset == "p_statistics") { if (tabletype == "mean") { json_output <- jsonlite::toJSON( x = list( "dataset" = meta$dataset[meta$variable == variable], "title" = varlabel, "variable" = variable, "statistics" = c("mean", "median"), "dimensions" = list( list("variable" = meta$variable[meta$variable == "alter_gr"], "label" = meta$label_de[meta$variable == "alter_gr"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$alter_gr))))))), list("variable" = meta$variable[meta$variable == "sex"], "label" = meta$label_de[meta$variable == "sex"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$sex))))))), list("variable" = meta$variable[meta$variable == "bula_h"], "label" = meta$label_de[meta$variable == "bula_h"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$bula_h))))))), list("variable" = meta$variable[meta$variable == "bildungsniveau"], "label" = meta$label_de[meta$variable == "bildungsniveau"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$bildungsniveau))))))), list("variable" = meta$variable[meta$variable == "sampreg"], "label" = meta$label_de[meta$variable == "sampreg"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$sampreg))))))), list("variable" = meta$variable[meta$variable == "migback"], "label" = meta$label_de[meta$variable == "migback"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$migback))))))), list("variable" = meta$variable[meta$variable == "regtyp"], "label" = meta$label_de[meta$variable == "regtyp"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$regtyp))))))) ), "description_de" = meta$description[meta$variable==variable], "start_year" = startyear, "end_year" = endyear, "types" = list("numerical") ), encoding = "UTF-8", pretty = TRUE, auto_unbox=TRUE ) file_handler <- file("meta.json") writeLines(json_output, exportpath, useBytes=TRUE) close(file_handler) } if (tabletype == "prop") { json_output <- jsonlite::toJSON( x = list( "dataset" = meta$dataset[meta$variable == variable], "title" = varlabel, "variable" = variable, "statistics" = "percent", "dimensions" = list( list("variable" = meta$variable[meta$variable == "alter_gr"], "label" = meta$label_de[meta$variable == "alter_gr"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$alter_gr))))))), list("variable" = meta$variable[meta$variable == "sex"], "label" = meta$label_de[meta$variable == "sex"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$sex))))))), list("variable" = meta$variable[meta$variable == "bula_h"], "label" = meta$label_de[meta$variable == "bula_h"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$bula_h))))))), list("variable" = meta$variable[meta$variable == "bildungsniveau"], "label" = meta$label_de[meta$variable == "bildungsniveau"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$bildungsniveau))))))), list("variable" = meta$variable[meta$variable == "sampreg"], "label" = meta$label_de[meta$variable == "sampreg"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$sampreg))))))), list("variable" = meta$variable[meta$variable == "migback"], "label" = meta$label_de[meta$variable == "migback"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$migback))))))), list("variable" = meta$variable[meta$variable == "regtyp"], "label" = meta$label_de[meta$variable == "regtyp"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$regtyp))))))) ), "description_de" = meta$description[meta$variable==variable], "start_year" = startyear, "end_year" = endyear, "types" = "categorical" ), encoding = "UTF-8", pretty = TRUE, auto_unbox=TRUE ) file_handler <- file("meta.json") writeLines(json_output, exportpath, useBytes=TRUE) close(file_handler) } } if (dataset == "h_statistics") { if (tabletype == "mean") { json_output <- jsonlite::toJSON( x = list( "dataset" = meta$dataset[meta$variable == variable], "title" = varlabel, "variable" = variable, "statistics" = c("mean", "median"), "dimensions" = list( list("variable" = meta$variable[meta$variable == "bula_h"], "label" = meta$label_de[meta$variable == "bula_h"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$bula_h))))))), list("variable" = meta$variable[meta$variable == "sampreg"], "label" = meta$label_de[meta$variable == "sampreg"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$sampreg))))))), list("variable" = meta$variable[meta$variable == "regtyp"], "label" = meta$label_de[meta$variable == "regtyp"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$regtyp))))))), list("variable" = meta$variable[meta$variable == "hhtyp"], "label" = meta$label_de[meta$variable == "hhtyp"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$hhtyp))))))), list("variable" = meta$variable[meta$variable == "quintil"], "label" = meta$label_de[meta$variable == "quintil"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$quintil))))))) ), "description_de" = meta$description[meta$variable==variable], "start_year" = startyear, "end_year" = endyear, "types" = list("numerical") ), encoding = "UTF-8", pretty = TRUE, auto_unbox=TRUE ) file_handler <- file("meta.json") writeLines(json_output, exportpath, useBytes=TRUE) close(file_handler) } if (tabletype == "prop") { json_output <- jsonlite::toJSON( x = list( "dataset" = meta$dataset[meta$variable == variable], "title" = varlabel, "variable" = variable, "statistics" = "percent", "dimensions" = list( list("variable" = meta$variable[meta$variable == "bula_h"], "label" = meta$label_de[meta$variable == "bula_h"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$bula_h))))))), list("variable" = meta$variable[meta$variable == "sampreg"], "label" = meta$label_de[meta$variable == "sampreg"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$sampreg))))))), list("variable" = meta$variable[meta$variable == "regtyp"], "label" = meta$label_de[meta$variable == "regtyp"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$regtyp))))))), list("variable" = meta$variable[meta$variable == "hhtyp"], "label" = meta$label_de[meta$variable == "hhtyp"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$hhtyp))))))), list("variable" = meta$variable[meta$variable == "quintil"], "label" = meta$label_de[meta$variable == "quintil"], "values" = list(as.list(str_trim(gsub("[[0-9]+]", "", levels(factor(data.file.fac$quintil))))))) ), "description_de" = meta$description[meta$variable==variable], "start_year" = startyear, "end_year" = endyear, "types" = "categorical" ), encoding = "UTF-8", pretty = TRUE, auto_unbox=TRUE ) file_handler <- file("meta.json") writeLines(json_output, exportpath, useBytes=TRUE) close(file_handler) } } }
Neue Variante:
################################################################################ # creation of json metadata #' @title json_create #' #' @description json_create creates json metadata #' #' @param table data.frame from which json metadata should be created #' @param variable variable name as character #' @param table_type table type (e.g. "numerical", "categorical") #' #' @author Stefan Zimmermann, \email{[email protected]} #' @keywords #' json_create <- function(table, variable, table_type) { all_grouping_variables <- metadaten_variables$variable[ metadaten_variables$statistical_type == "dimension" & metadaten_variables$variable != "syear" ] exportfile <- paste0(export_path, table_type, "/", variable, "/meta.json") grouping_information <- list(NULL) for (groupingvar in all_grouping_variables) { grouping_information[[groupingvar]] <- list( "variable" = metadaten_variables$variable[ metadaten_variables$variable == groupingvar ], "label" = metadaten_variables$label_de[ metadaten_variables$variable == groupingvar ], "values" = list(as.list(stringr::str_trim( gsub("[[0-9]+]", "", levels( factor(datafile_with_labels[[groupingvar]]) )) ))) ) } statistics <- list(NULL) statistics[["numerical"]] <- numeric_statistics_column_names statistics[["categorical"]] <- categorical_statistics_column_names json_output <- jsonlite::toJSON( x = list( "title" = metadaten_variables$label_de[ metadaten_variables$variable == variable ], "variable" = metadaten_variables$variable[ metadaten_variables$variable == variable ], "statistics" = statistics[[table_type]], "dimensions" = grouping_information, "description_de" = metadaten_variables$description_de[ metadaten_variables$variable == variable ], "start_year" = min(table$year), "end_year" = max(table$year), "types" = table_type ), encoding = "UTF-8", pretty = TRUE, auto_unbox = TRUE ) file_handler <- file("meta.json") writeLines(json_output, exportfile, useBytes = TRUE) close(file_handler) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Urzustand:
Neue Variante:
The text was updated successfully, but these errors were encountered: