Commit 841190e3 authored by GNajeral's avatar GNajeral

Updated valid_variables_script2

parent e2324ef7
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment