From 841190e3e26f74d76b14d72f028c9a371cdc3340 Mon Sep 17 00:00:00 2001 From: GNajeral <90567992+GNajeral@users.noreply.github.com> Date: Fri, 3 Mar 2023 13:59:36 +0100 Subject: [PATCH] Updated valid_variables_script2 --- valid_variables_script2.R | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/valid_variables_script2.R b/valid_variables_script2.R index 1b2221d..5ce27d1 100644 --- a/valid_variables_script2.R +++ b/valid_variables_script2.R @@ -132,8 +132,8 @@ is_number <- function(x){ check_values_format <- function(valid_columns, codebook_param){ res <- "" variables_out_of_range = "Variables out of range:" - for(i in 1:length(valid_columns[[1]])){ - +# for(i in 1:length(valid_columns[[1]])){ + for(i in 1:9){ current_column <- valid_columns[[1]][[i]] print(current_column) variable_type <- codebook_param$Variable.type[codebook$Harmonised.variable.name == current_column] @@ -141,6 +141,8 @@ check_values_format <- function(valid_columns, codebook_param){ if (is.na(variable_type)){ next } + + print(variable_type) if(variable_type == "Continuous"){ @@ -149,8 +151,12 @@ check_values_format <- function(valid_columns, codebook_param){ ### parse del formato de una variable continua ## ## esta sentencia funciona codebook$Possible.values.format[codebook$Harmonised.variable.name == "CMXDE"] pruebala en el interprete. value_format <- strsplit(codebook_param$Possible.values.format[codebook_param$Harmonised.variable.name == current_column], " / ")[[1]] - high_limit <- gsub(",", ".", (sub("-.*", "", value_format[1]))) - low_limit <- gsub(",", ".", (sub(".*-", "", value_format[1]))) + high_limit <- str_trim(gsub(",", ".", (sub("-.*", "", value_format[1])))) + low_limit <- str_trim(gsub(",", ".", (sub(".*-", "", value_format[1])))) + if(low_limit == ""){ + high_limit <- str_trim(sub(",.*", "", value_format[1])) + low_limit <- str_trim(strtrimsub(".*,", "", value_format[1])) + } ### parse del formato de una variable continua ## tryCatch( @@ -190,8 +196,29 @@ check_values_format <- function(valid_columns, codebook_param){ ################## FIN ESTO PODRÍA IR EN UNA FUNC DIFERENTE ############# }else if (variable_type == "Categorical" || variable_type == "Binary"){ - contingency_table <- ds.table(paste("data$",current_column)) - counts <- contingency_table[[1]][[3]] + value_format <- lapply(strsplit(mierda, "/") , str_trim)[[1]] + tryCatch( + error = function(cnd) { + if(grepl("list them with datashield.errors()",cnd)) + error <- paste("Unable to analyse data" , datashield.errors() , sep = " ") + else + error <- paste("Unable to analyse data" , cnd, sep = " ") + print(error) + res <- c(res, error) + }, + { + contingency_table <- ds.table(paste("data$",current_column,sep="")) + row_names <- rownames(contingency_table[[1]][[3]]) + for (i in 1:length(row_names)) { + if(row_names[i] == "NA") + next + if(!row_names[i] %in% value_format){ + variables_out_of_range <- paste(variables_out_of_range, current_column, sep = " ") + print(paste(current_column, "does not follow the established format", sep=" ")) + } + } + } + ) } } return (variables_out_of_range) -- 2.24.1