diff --git a/DESCRIPTION b/DESCRIPTION index 200bf1f..2e86ed7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,7 +45,11 @@ Depends: truncnorm, OpenRepGrid Suggests: - shiny + shiny, + testthat (>= 2.1.0), + utils URL: https://github.com/unhcr/koboloadeR BugReports: https://github.com/unhcr/koboloadeR/issues RoxygenNote: 6.1.1 +VignetteBuilder: utils + diff --git a/NAMESPACE b/NAMESPACE index b81d846..7ccc7f0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -43,6 +43,7 @@ export(kobo_histo) export(kobo_histo_print) export(kobo_indicator) export(kobo_label) +export(kobo_left_align) export(kobo_load_data) export(kobo_load_packages) export(kobo_map_cat) @@ -65,6 +66,10 @@ export(kobo_time_parser_UTC) export(kobo_to_xlsform) export(kobo_trend) export(kobo_trend_report) +export(kobo_unhcr_style_bar) +export(kobo_unhcr_style_histo) +export(kobo_unhcr_style_map) +export(kobo_unhcr_style_scatter) export(kobo_weight) export(ltbl) export(multresponse) diff --git a/R/kobo_anonymise.R b/R/kobo_anonymise.R index 3703545..220daa5 100644 --- a/R/kobo_anonymise.R +++ b/R/kobo_anonymise.R @@ -35,8 +35,6 @@ #' #' @author Edouard Legoupil #' -#' @examples -#' kobo_anonymise() #' #' @export kobo_anonymise #' diff --git a/R/kobo_create_indicators.R b/R/kobo_create_indicators.R index 0bd600b..cf3ec49 100644 --- a/R/kobo_create_indicators.R +++ b/R/kobo_create_indicators.R @@ -6,7 +6,7 @@ #' #' @param form The full filename of the form to be accessed (xls or xlsx file). #' It is assumed that the form is stored in the data folder. -#' +#' #' #' @return No return, all results will be saved inside new CSV files #' @@ -24,43 +24,65 @@ #' kobo_create_indicators <- function(form = "form.xls") { + + mainDir <- kobo_getMainDirectory() + form_tmp <- paste(mainDir, "data", form, sep = "/", collapse = "/") + tryCatch({ +<<<<<<< HEAD + +======= mainDir <- kobo_getMainDirectory() form_tmp <- paste(mainDir, "data", form, sep = "/", collapse = "/") - + ## Load all required packages kobo_load_packages() library(koboloadeR) - + ## load all required data files ######################################### cat("\n\nload all required data files..\n") dataBeginRepeat <- kobo_get_begin_repeat() dataBeginRepeat <- dataBeginRepeat$names for (dbr in dataBeginRepeat) { - dataFrame <- read.csv(paste(mainDir,"/data/",dbr,"_edited.csv",sep = ""),stringsAsFactors = F) + dataFrame <- read.csv(paste(mainDir,"/data/",dbr,"_edited.csv",sep = ""),stringsAsFactors = F) assign(dbr, dataFrame) } - + +>>>>>>> fffa73afd5387d145dea1058ded0957512987da9 #### Load and test i indicators ############################################################################# #library(readxl) tried <- try(read_excel(form_tmp, sheet = "indicator"), silent = TRUE) if (inherits(tried, "try-error")) { - writeLines("There was an error: You have not defined indicators within your xlsform file. \n") - + writeLines("Note that you have not defined (or defined correctly) indicators within your xlsform file. \n") + } else { - + rm(tried) + ## Load all required packages + kobo_load_packages() + # library(koboloadeR) + + ## load all required data files ######################################### + cat("\n\nload all required data files..\n") + dataBeginRepeat <- kobo_get_begin_repeat() + dataBeginRepeat <- dataBeginRepeat$names + for (dbr in dataBeginRepeat) { + dataFrame <- read.csv(paste(mainDir,"/data/",dbr,"-edited.csv",sep = ""),stringsAsFactors = F) + assign(dbr, dataFrame) + } + + indicator <- read_excel(form_tmp, sheet = "indicator") if(nrow(indicator)==0){ - writeLines("There was an error: You have not defined indicators within your xlsform file. \n") - + writeLines("Note that you have not defined (or defined correctly) indicators within your xlsform file. \n") + } else { ## Load data & dico ############################################################################# #form <- "form.xls" ## Run this only after data cleaning dico <- read.csv(paste0(mainDir,"/data/dico_",form,".csv"), encoding = "UTF-8", na.strings = "") - + ## Create the dicotemp ############################################################################# #names(dico) dicotemp <- data.frame(c("trigger")) @@ -68,22 +90,26 @@ kobo_create_indicators <- function(form = "form.xls") { #dicotemp$type <- "trigger" dicotemp$name <- "trigger" dicotemp$fullname <- "trigger" - dicotemp$label <- "trigger" + # dicotemp$label <- "trigger" dicotemp$labelReport <- "trigger" + dicotemp$hintReport <- "trigger" dicotemp$chapter <- "trigger" dicotemp$disaggregation <- "trigger" dicotemp$correlate <- "trigger" dicotemp$anonymise <- "trigger" - - dicotemp$structuralequation <- "trigger" + + dicotemp$structuralequation.risk <- "trigger" + dicotemp$structuralequation.coping <- "trigger" + dicotemp$structuralequation.resilience <- "trigger" + dicotemp$clean <- "trigger" dicotemp$cluster <- "trigger" dicotemp$predict <- "trigger" dicotemp$variable <- "trigger" dicotemp$mappoint <- "trigger" dicotemp$mappoly <- "trigger" - - + + dicotemp$listname <- "trigger" dicotemp$qrepeat <- "trigger" dicotemp$qrepeatlabel <- "trigger" @@ -97,105 +123,112 @@ kobo_create_indicators <- function(form = "form.xls") { dicotemp$recategorise <- "trigger" dicotemp$formpart <- "trigger" dicotemp$indic <- "feature" - - ####Load data analysis plan############################################################################# - #library(readxl) - indicator <- read_excel(form_tmp, sheet = "indicator") - + + ## Need to check that all column are presents... - - + + ## Load indicator info ############################################################################# - + for (i in 1:nrow(indicator)) - + { + # i <- 1 indicator.type <- as.character(indicator[ i, c("type")]) indicator.fullname <- as.character(indicator[ i, c("fullname")]) - indicator.label <- as.character(indicator[ i, c("label")]) - indicator.report <- as.character(indicator[ i, c("label")]) + # indicator.label <- as.character(indicator[ i, c("label")]) + indicator.labelReport <- as.character(indicator[ i, c("labelReport")]) + indicator.hintReport <- as.character(indicator[ i, c("hintReport")]) indicator.chapter <- as.character(indicator[ i, c("chapter")]) indicator.disaggregation <- as.character(indicator[ i, c("disaggregation")]) indicator.correlate <- as.character(indicator[ i, c("correlate")]) - indicator.sensitive <- as.character(indicator[ i, c("sensitive")]) indicator.anonymise <- as.character(indicator[ i, c("anonymise")]) indicator.frame <- as.character(indicator[ i, c("frame")]) indicator.listname <- as.character(indicator[ i, c("listname")]) indicator.calculation <- as.character(indicator[ i, c("calculation")]) - - - indicator.structuralequation <- as.character(indicator[ i, c("structuralequation")]) + + + indicator.structuralequation.risk <- as.character(indicator[ i, c("structuralequation.risk")]) + indicator.structuralequation.coping <- as.character(indicator[ i, c("structuralequation.coping")]) + indicator.structuralequation.resilience <- as.character(indicator[ i, c("structuralequation.resilience")]) indicator.cluster <- as.character(indicator[ i, c("cluster")]) indicator.predict <- as.character(indicator[ i, c("predict")]) indicator.variable <- as.character(indicator[ i, c("variable")]) indicator.mappoint <- as.character(indicator[ i, c("mappoint")]) indicator.mappoly <- as.character(indicator[ i, c("mappoly")]) - - - cat(paste0(i, "- Load indicator: ", indicator.label," of type: ",indicator.type,"\n")) - + + + cat(paste0(i, "- Load indicator: ", indicator.labelReport," of type: ",indicator.type,"\n")) + ## Build and run the formula to insert the indicator in the right frame ########################### indic.formula <- paste0(indicator.frame,"$",indicator.fullname," <- ",indicator.calculation ) if (file.exists(paste0(mainDir,"/code/temp.R") )) file.remove(paste0(mainDir,"/code/temp.R")) + + + cat(paste('### Script to generate indicator: ',indicator.labelReport,sep = ""), file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) cat(paste('form <- "',form,'"',sep = ""), file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) cat("mainDir <- kobo_getMainDirectory()", file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) cat('form_tmp <- paste(mainDir, "data", form, sep = "/", collapse = "/")', file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) cat('dataBeginRepeat <- kobo_get_begin_repeat()', file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) cat('dataBeginRepeat <- dataBeginRepeat$names', file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) - cat('MainDataFrame_edited <- read.csv(paste(mainDir,"/data/MainDataFrame_edited.csv",sep = ""), encoding = "UTF-8", na.strings = "NA")', file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) - - cat(' - for (dbr in dataBeginRepeat) { - dataFrame <- read.csv(paste(mainDir,"/data/",dbr,"_edited.csv",sep = ""),stringsAsFactors = F) + + cat('MainDataFrame <- read.csv(paste(mainDir,"/data/MainDataFrame-edited.csv",sep = ""), encoding = "UTF-8", na.strings = "NA")', file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) + + cat('for (dbr in dataBeginRepeat) { + dataFrame <- read.csv(paste(mainDir,"/data/",dbr,"-edited.csv",sep = ""),stringsAsFactors = F) + assign(dbr, dataFrame) - } - ', file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) - + }', file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) + cat(indic.formula, file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) cat("####", file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) - + ## do a check on indicator variable type indicator.type2 <- indicator.type ifelse(indicator.type == "select_one", indicator.type2 <- "character", indicator.type2 <- indicator.type) - - + + cat(paste0(indicator.frame,"$",indicator.fullname," <- as.",indicator.type2,"(",indicator.frame,"$",indicator.fullname,")"), file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) cat(paste0("str(",indicator.frame,"$",indicator.fullname,")"), file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) cat(paste0("summary(",indicator.frame,"$",indicator.fullname,")"), file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) - - if(indicator.frame == "MainDataFrame_edited"){ - cat('write.csv(MainDataFrame_edited, paste(mainDir,"/data/MainDataFrame_edited.csv",sep = ""), row.names = FALSE, na = "")', file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) - }else{ - cat(paste('dbr<-"',indicator.frame,'"',sep = "")) - cat('write.csv(eval(as.name(dbr)),paste(mainDir,"/data/",dbr,"_edited.csv",sep = ""), row.names = FALSE, na = "")', file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) - } - + + if (indicator.frame == "MainDataFrame") { + cat('write.csv(MainDataFrame, paste(mainDir,"/data/MainDataFrame-edited.csv",sep = ""), row.names = FALSE, na = "")', file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) + }else{ + cat(paste('dbr<-"',indicator.frame,'"',sep = "")) + cat('write.csv(eval(as.name(dbr)),paste(mainDir,"/data/",dbr,"-edited.csv",sep = ""), row.names = FALSE, na = "")', file = paste0(mainDir,"/code/temp.R") , sep = "\n", append = TRUE) + } + + source(paste0(mainDir,"/code/temp.R")) - cat(paste0(i, "- Executed indicator: ", indicator.label,"\n")) + cat(paste0(i, "- Executed indicator: ", indicator.labelReport,"\n")) if (file.exists(paste0(mainDir,"/code/temp.R"))) file.remove(paste0(mainDir,"/code/temp.R")) - + ## Insert the indicator in a temp dico frame to be appended to the full dico ###################### - + dicotemp1 <- data.frame(c("trigger")) names(dicotemp1)[1] <- "type" dicotemp1$type <- indicator.type dicotemp1$name <- indicator.fullname dicotemp1$fullname <- indicator.fullname - dicotemp1$label <- indicator.label - dicotemp1$labelReport <- indicator.report + #dicotemp1$label <- indicator.label + dicotemp1$labelReport <- indicator.labelReport + dicotemp1$hintReport <- indicator.hintReport dicotemp1$chapter <- indicator.chapter dicotemp1$disaggregation <- indicator.disaggregation dicotemp1$correlate <- indicator.correlate dicotemp1$anonymise <- indicator.anonymise - - dicotemp1$structuralequation <- indicator.structuralequation + + dicotemp1$structuralequation.risk <- indicator.structuralequation.risk + dicotemp1$structuralequation.coping <- indicator.structuralequation.coping + dicotemp1$structuralequation.resilience <- indicator.structuralequation.resilience dicotemp1$clean <- " " dicotemp1$cluster <- indicator.cluster dicotemp1$predict <- indicator.predict dicotemp1$variable <- indicator.variable dicotemp1$mappoint <- indicator.mappoint dicotemp1$mappoly <- indicator.mappoly - + dicotemp1$listname <- indicator.listname dicotemp1$qrepeat <- " " dicotemp1$qrepeatlabel <- indicator.frame @@ -208,167 +241,187 @@ kobo_create_indicators <- function(form = "form.xls") { dicotemp1$recategorise <- " " dicotemp1$formpart <- " " dicotemp1$indic <- "feature" - + dicotemp <- rbind(dicotemp,dicotemp1) - + } ## Append indicators in the dico ############################################################################# - + ## removing first line dicotemp <- dicotemp[ 2:nrow(dicotemp), ] - + ### mergin choices from the newly created indicators ################################################################# - + cat("\n\n\n It's assumed that the modalities for newly calculated categoric indicators are in the same xlsform - choices worksheet \n\n\n\n") choices <- read_excel(form_tmp, sheet = "choices") - + #rm(choices) - names(choices)[names(choices) == "label::English"] <- "label" - names(choices)[names(choices) == "label::english"] <- "label" + names(choices)[names(choices) == "labelReport"] <- "label" + #names(choices)[names(choices) == "label::english"] <- "label" names(choices)[names(choices) == "list name"] <- "listname" names(choices)[names(choices) == "list_name"] <- "listname" - + ## Remove trailing space choices$listname <- trim(choices$listname) choices$label <- trim(choices$label) - + if ("labelReport" %in% colnames(choices)) { - cat("12 - Good: You have a column `labelReport` in your `choices` worksheet.\n"); + cat(" Good: You have a column `labelReport` in your `choices` worksheet.\n"); } else - {cat("12 - No column `labelReport` in your `choices` worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `labelReport` in your `choices` worksheet. Creating a dummy one for the moment...\n"); choices[,"labelReport"] <- substr(choices[,"label"],1,80)} - + if ("order" %in% colnames(choices)) { cat(" Good: You have a column `order` in your `choices` worksheet.\n"); } else {cat(" No column `order` in your `choices` worksheet. Creating a dummy one for the moment...\n"); choices$order <- ""} - + if ("weight" %in% colnames(choices)) { cat(" Good: You have a column `weight` in your `choices` worksheet.\n"); } else - {cat("13 - No column `weight` in your `choices` worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `weight` in your `choices` worksheet. Creating a dummy one for the moment...\n"); choices$weight <- ""} - + if ("recategorise" %in% colnames(choices)) { cat(" Good: You have a column `recategorise` in your `choices` worksheet.\n"); } else {cat(" No column `recategorise` in your `choices` worksheet. Creating a dummy one for the moment...\n"); choices$recategorise <- ""} - + if ("score" %in% colnames(choices)) { cat(" Good: You have a column `score` in your `choices` worksheet.\n"); } else {cat(" No column `score` in your `choices` worksheet. Creating a dummy one for the moment...\n"); choices$score <- ""} - + choices <- choices[,c("listname", "name", "label", "order", "weight","score","recategorise")] names(choices)[names(choices) == "label"] <- "labelchoice" #rm(choices) - - dicotemp.choice <- dicotemp[ !(is.na(dicotemp$listname)), c( "type", "name", "fullname", "label", "labelReport", + + dicotemp.choice <- dicotemp[ !(is.na(dicotemp$listname)), c( "type", "name", "fullname", "label", "labelReport","hintReport", "chapter", "disaggregation","correlate", "anonymise", - "structuralequation", "clean", "cluster", "predict", + "structuralequation.risk","structuralequation.coping","structuralequation.resilience", + "clean", "cluster", "predict", "variable", "mappoint", "mappoly", "listname", "qrepeat", "qrepeatlabel","qlevel","qgroup" )] - + choices2 <- join(x = dicotemp.choice, y = choices, by = "listname", type = "left") - + choices2$type <- with(choices2, ifelse(grepl("select_one", ignore.case = TRUE, fixed = FALSE, useBytes = FALSE, choices2$type), paste0("select_one_d"),choices2$type)) - + choices2$type <- with(choices2, ifelse(grepl("select_multiple_d", ignore.case = TRUE, fixed = FALSE, useBytes = FALSE, choices2$type), paste0("select_multiple"),choices2$type)) - + names(choices2)[2] <- "nameq" names(choices2)[3] <- "nameqfull" names(choices2)[4] <- "labelq" choices2$labelfull <- paste0(choices2$labelq, sep = ": ", choices2$labelchoice) choices2$namefull <- paste0(choices2$nameqfull, sep = ".", choices2$name) - - - + + + #### Now Row bind questions & choices######################################################################################################## - choices3 <- choices2[ ,c("type", "name", "namefull", "labelfull", "labelReport", + choices3 <- choices2[ ,c("type", "name", "namefull", "labelfull", "labelReport","hintReport", "chapter", "disaggregation","correlate", "anonymise", - "structuralequation", "clean", "cluster", "predict", + "structuralequation.risk","structuralequation.coping","structuralequation.resilience", + "clean", "cluster", "predict", "variable", "mappoint", "mappoly", "listname", "qrepeat", "qrepeatlabel","qlevel","qgroup", "labelchoice", "order", "weight","score", "recategorise")] - - + + names(choices3)[names(choices3) == "namefull"] <- "fullname" names(choices3)[names(choices3) == "labelfull"] <- "label" - - - dicotemp <- dicotemp[,c( "type", "name", "fullname", "label", "labelReport", + + + dicotemp <- dicotemp[,c( "type", "name", "fullname", "label", "labelReport","hintReport", "chapter", "disaggregation","correlate", "anonymise", - "structuralequation", "clean", "cluster", "predict", + "structuralequation.risk","structuralequation.coping","structuralequation.resilience", + "clean", "cluster", "predict", "variable", "mappoint", "mappoly", "listname", "qrepeat", "qrepeatlabel","qlevel","qgroup", "labelchoice", "order", "weight","score", "recategorise")] - + ### Check -- normally there should not be duplicate - - + + dicotemp$formpart <- "questions" choices3$formpart <- "answers" - + dicotemp <- rbind(dicotemp,choices3) - - + + dicotemp$indic <- "feature" dico$indic <- "data" - - dico$structuralequation <- NA - + + + dicotemp$relevant <- "" + dicotemp$required <- "" + dicotemp$constraint <- "" + dicotemp$repeat_count <- "" + + #names(dico) #names(dicotemp) - dico <- dico[ , c( "type", "name", "fullname", "label", "labelReport", + dico <- dico[ , c( "type", "name", "fullname", "label", "labelReport","hintReport", "chapter", "disaggregation","correlate", "anonymise", - "structuralequation", "clean", "cluster", "predict", - "variable", "mappoint", "mappoly", "listname", - "qrepeat", "qrepeatlabel","qlevel","qgroup", + "structuralequation.risk","structuralequation.coping","structuralequation.resilience", + "anonymise", "clean", "cluster", "predict", "variable", "mappoint", "mappoly", + + "relevant", "required", "constraint", "repeat_count", + + "listname","qrepeat", "qrepeatlabel","qlevel","qgroup", "labelchoice", "order", "weight","score", "recategorise", "formpart", "indic" )] - dicotemp <- dicotemp[ , c( "type", "name", "fullname", "label", "labelReport", - "chapter", "disaggregation","correlate", "anonymise", - "structuralequation", "clean", "cluster", "predict", - "variable", "mappoint", "mappoly", "listname", - "qrepeat", "qrepeatlabel","qlevel","qgroup", - "labelchoice", "order", "weight","score", - "recategorise", "formpart", "indic" )] - - + + + dicotemp <- dicotemp[ , c("type", "name", "fullname", "label", "labelReport","hintReport", + "chapter", "disaggregation","correlate", "anonymise", + "structuralequation.risk","structuralequation.coping","structuralequation.resilience", + "anonymise", "clean", "cluster", "predict", "variable", "mappoint", "mappoly", + + "relevant", "required", "constraint", "repeat_count", + + "listname","qrepeat", "qrepeatlabel","qlevel","qgroup", + "labelchoice", "order", "weight","score", + "recategorise", "formpart", "indic" )] + + dico <- rbind(dico,dicotemp) - + rm(dicotemp,dicotemp1, choices, choices2, choices3, dicotemp.choice) - - MainDataFrame_edited <- read.csv(paste(mainDir,"/data/MainDataFrame_edited.csv",sep = ""), encoding = "UTF-8", na.strings = "NA") + + + MainDataFrame <- read.csv(paste(mainDir,"/data/MainDataFrame-edited.csv",sep = ""), encoding = "UTF-8", na.strings = "NA") ## label Variables cat("\n\n quick check on labeling\n") - MainDataFrame_edited <- kobo_label(MainDataFrame_edited , dico) + MainDataFrame <- kobo_label(MainDataFrame , dico) for (dbr in dataBeginRepeat) { - dataFrame <- read.csv(paste(mainDir,"/data/",dbr,"_edited.csv",sep = ""),stringsAsFactors = F) + dataFrame <- read.csv(paste(mainDir,"/data/",dbr,"-edited.csv",sep = ""),stringsAsFactors = F) + dataFrame <- kobo_label(dataFrame, dico) write.csv(dataFrame,paste(mainDir,"/data/",dbr,"_edited.csv",sep = ""), row.names = FALSE, na = "") } cat("\n\nWrite dico\n") write.csv(dico, paste0(mainDir,"/data/dico_",form,".csv"), row.names = FALSE, na = "") - write.csv(MainDataFrame_edited, paste(mainDir,"/data/MainDataFrame_edited.csv",sep = ""), row.names = FALSE, na = "") - + + write.csv(MainDataFrame, paste(mainDir,"/data/MainDataFrame-edited.csv",sep = ""), row.names = FALSE, na = "") + + } } }, error = function(err) { - print("kobo_create_indicators_ERROR") + print("There as an error in the indicator creation step!!! \n\n") return(structure(err, class = "try-error")) }) -} \ No newline at end of file +} diff --git a/R/kobo_crunching_report.R b/R/kobo_crunching_report.R index 049d932..1ecdc26 100644 --- a/R/kobo_crunching_report.R +++ b/R/kobo_crunching_report.R @@ -22,7 +22,7 @@ #' @export kobo_crunching_report #' -kobo_crunching_report <- function(form = "form.xls", app="console") { +kobo_crunching_report <- function(form = "form.xls", app = "console") { tryCatch({ if (app == "shiny") { progress <- shiny::Progress$new() @@ -43,11 +43,13 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { configInfo <- configInfo[!is.na(configInfo$name),] mainDir <- kobo_getMainDirectory() form_tmp <- paste(mainDir, "data", form, sep = "/", collapse = "/") - library(koboloadeR) + #library(koboloadeR) ### Load the data cat("\n\n Loading data. It is assumed that the cleaning, weighting & re-encoding has been done previously \n") - MainDataFrame_edited <- read.csv(paste(mainDir,"/data/MainDataFrame.csv",sep = ""), encoding = "UTF-8", na.strings = "") + + MainDataFrame <- read.csv(paste(mainDir,"/data/MainDataFrame-encoded.csv",sep = ""), encoding = "UTF-8", na.strings = "") + ###Form########################################## ## Load form @@ -66,13 +68,17 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { progress$set(message = "Labelling variables in the Main Data File in progress...") updateProgress() } - MainDataFrame_edited <- kobo_label(MainDataFrame_edited , dico) + + MainDataFrame <- kobo_label(MainDataFrame , dico) + cat("\n\nload all required data files..\n") dataBeginRepeat <- kobo_get_begin_repeat() dataBeginRepeat <- dataBeginRepeat$names for (dbr in dataBeginRepeat) { - dataFrame <- read.csv(paste(mainDir,"/data/",dbr,"_edited.csv",sep = ""),stringsAsFactors = F) + + dataFrame <- read.csv(paste(mainDir,"/data/",dbr,"-encoded.csv",sep = ""),stringsAsFactors = F) + assign(dbr, kobo_label(dataFrame, dico)) if (app == "shiny") { progress$set(message = paste("Labelling variables in",dbr,"File in progress...")) @@ -130,6 +136,7 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { for (i in 1:nrow(chapters) ) { + # i <-1 chaptersname <- as.character(chapters[ i , 1]) if (app == "shiny") { progress$set(message = paste(i, " - Render chapter for ",as.character(chapters[ i , 1]))) @@ -145,7 +152,7 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { ## TO DO : put in configuration wethere report should be portrait or landscape cat("---", file = chapter.name , sep = "\n", append = TRUE) cat(paste("title: \"Data Crunching Report: ",chaptersname , "- Draft not for distribution. \"", sep = ""), file = chapter.name , sep = "\n", append = TRUE) - cat("author: \"Generated with [Koboloader](https://github.com/unhcr/koboloadeR) \"", file = chapter.name , sep = "\n", append = TRUE) + cat("author: \"Generated with [Koboloader](https://unhcr.github.io/koboloadeR/docs) \"", file = chapter.name , sep = "\n", append = TRUE) cat("date: \" `r format(Sys.Date(), '%d %B %Y')`\"", file = chapter.name , sep = "\n", append = TRUE) cat("always_allow_html: yes", file = chapter.name , sep = "\n", append = TRUE) cat("output:",file = chapter.name , sep = "\n", append = TRUE) @@ -166,6 +173,7 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat("mainDirroot <- substring(mainDir, 0 , nchar(mainDir) - 5)", file = chapter.name , sep = "\n", append = TRUE) + cat("## Load all required packages", file = chapter.name , sep = "\n", append = TRUE) cat("library(tidyverse)", file = chapter.name , sep = "\n", append = TRUE) cat("library(ggthemes)", file = chapter.name , sep = "\n", append = TRUE) cat("library(plyr)", file = chapter.name , sep = "\n", append = TRUE) @@ -179,28 +187,33 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat("library(survey)", file = chapter.name , sep = "\n", append = TRUE) cat("library(knitr)", file = chapter.name , sep = "\n", append = TRUE) cat("library(rmarkdown)", file = chapter.name , sep = "\n", append = TRUE) - - #("source(paste0(mainDirroot,\"/code/0-theme.R\"))", file = chapter.name , sep = "\n", append = TRUE) + cat("library(ggpubr)", file = chapter.name , sep = "\n", append = TRUE) + cat("library(grid)", file = chapter.name , sep = "\n", append = TRUE) cat("library(koboloadeR)", file = chapter.name , sep = "\n", append = TRUE) - cat("## Load all required packages", file = chapter.name , sep = "\n", append = TRUE) - #cat("kobo_load_data()", file = chapter.name , sep = "\n", append = TRUE) - # cat("source(paste0(mainDirroot,\"/code/0-packages.R\"))", file = chapter.name , sep = "\n", append = TRUE) + cat("options(scipen = 999) # turn-off scientific notation like 1e+48", file = chapter.name , sep = "\n", append = TRUE) + cat("## Provide below the name of the form in xsl form - format should be xls not xlsx", file = chapter.name , sep = "\n", append = TRUE) cat(paste0("form <- \"",form,"\""), file = chapter.name , sep = "\n", append = TRUE) cat("dico <- read.csv(paste0(mainDirroot,\"/data/dico_\",form,\".csv\"), encoding = \"UTF-8\", na.strings = \"\")", file = chapter.name , sep = "\n", append = TRUE) ## TO DO: Use config file to load the different frame - cat("MainDataFrame_edited <- read.csv(paste0(mainDirroot,\"/data/MainDataFrame_edited.csv\"), encoding = \"UTF-8\", na.strings = \"\")", file = chapter.name , sep = "\n", append = TRUE) + + + cat("MainDataFrame <- read.csv(paste0(mainDirroot,\"/data/MainDataFrame-encoded.csv\"), encoding = \"UTF-8\", na.strings = \"\")", file = chapter.name , sep = "\n", append = TRUE) + for (dbr in dataBeginRepeat) { - cat(paste(dbr, "<- read.csv(paste0(mainDirroot,\"/data/",dbr,"_edited.csv\"), encoding = \"UTF-8\", na.strings = \"\")", sep = ""), file = chapter.name , sep = "\n", append = TRUE) + cat(paste(dbr, " <- read.csv(paste0(mainDirroot,\"/data/",dbr,"-encoded.csv\"), encoding = \"UTF-8\", na.strings = \"\")", sep = ""), file = chapter.name , sep = "\n", append = TRUE) + } cat("\n", file = chapter.name , sep = "\n", append = TRUE) cat("## label Variables", file = chapter.name , sep = "\n", append = TRUE) - cat("MainDataFrame_edited <- kobo_label(MainDataFrame_edited , dico)", file = chapter.name , sep = "\n", append = TRUE) + + cat("MainDataFrame <- kobo_label(MainDataFrame , dico)", file = chapter.name , sep = "\n", append = TRUE) + for (dbr in dataBeginRepeat) { cat(paste(dbr, " <- kobo_label(",dbr ," , dico)", sep = ""), file = chapter.name , sep = "\n", append = TRUE) } @@ -227,28 +240,37 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat("\n", file = chapter.name , sep = "\n", append = TRUE) cat("## Create weighted survey object", file = chapter.name , sep = "\n", append = TRUE) + ## If no weight, the weighted object is unweigthted - if(configInfo[configInfo$name == "sample_type","value"] == "No sampling(type 1)"){ + if (configInfo[configInfo$name == "sample_type","value"] == "No sampling (type 1)") { ## If no weight, the weighted object is unweigthted - cat("MainDataFrame_edited.survey <- svydesign(ids = ~ 1 , data = MainDataFrame_edited )", file = chapter.name , sep = "\n", append = TRUE) + cat("MainDataFrame.survey <- svydesign(ids = ~ 1 , data = MainDataFrame )", file = chapter.name , sep = "\n", append = TRUE) + for (dbr in dataBeginRepeat) { cat(paste(dbr,".survey <- svydesign(ids = ~ 1 , data = ",dbr," )", sep = ""), file = chapter.name , sep = "\n", append = TRUE) } - }else if(configInfo[configInfo$name == "sample_type","value"] == "Cluster sample (type 2)"){ ## with clusters - cat(paste("MainDataFrame_edited.survey <- svydesign(ids = ~ ", configInfo[configInfo$name == "variable_name","value"],", data = MainDataFrame_edited, weights = ~ ", configInfo[configInfo$name == "weightsVariable","value"]," , fpc = ~ fpc )", sep = ""), file = chapter.name , sep = "\n", append = TRUE) + + }else if (configInfo[configInfo$name == "sample_type","value"] == "Cluster sample (type 2)") { + ## with clusters + cat(paste("MainDataFrame.survey <- svydesign(ids = ~ ", configInfo[configInfo$name == "variable_name","value"],", data = MainDataFrame, weights = ~ ", configInfo[configInfo$name == "weightsVariable","value"]," , fpc = ~ fpc )", sep = ""), file = chapter.name , sep = "\n", append = TRUE) + for (dbr in dataBeginRepeat) { cat(paste(dbr,".survey <- svydesign(ids = ~ ", configInfo[configInfo$name == "variable_name","value"],", data = ",dbr,", weights = ~ ", configInfo[configInfo$name == "weightsVariable","value"]," , fpc = ~ fpc )", sep = ""), file = chapter.name , sep = "\n", append = TRUE) } - }else if(configInfo[configInfo$name == "sample_type","value"] == "Stratified sample (type 3)"){ ## with strata - cat(paste("MainDataFrame_edited.survey <- svydesign(id=~1, strata= ~ ", configInfo[configInfo$name == "variable_name","value"]," ,check.strata = TRUE, data = MainDataFrame_edited, weights = ~ ", configInfo[configInfo$name == "weightsVariable","value"]," )", sep=""), file = chapter.name , sep = "\n", append = TRUE) + + }else if (configInfo[configInfo$name == "sample_type","value"] == "Stratified sample (type 3)") { + ## with strata + cat(paste("MainDataFrame.survey <- svydesign(id=~1, strata= ~ ", configInfo[configInfo$name == "variable_name","value"]," ,check.strata = TRUE, data = MainDataFrame, weights = ~ ", configInfo[configInfo$name == "weightsVariable","value"]," )", sep = ""), file = chapter.name , sep = "\n", append = TRUE) + for (dbr in dataBeginRepeat) { cat(paste(dbr,".survey <- svydesign(id=~1, strata= ~ ", configInfo[configInfo$name == "variable_name","value"]," ,check.strata = TRUE, data = ",dbr,", weights = ~ ", configInfo[configInfo$name == "weightsVariable","value"]," )", sep = ""), file = chapter.name , sep = "\n", append = TRUE) } } + ## with strata #cat("MainDataFrame_edited.survey <- svydesign(id=~1, strata= ~ RecordCategory ,check.strata = TRUE, data = MainDataFrame_edited, weights = ~ WeightingCoefficient )", file = chapter.name , sep = "\n", append = TRUE) @@ -262,6 +284,7 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { # cat("br1.survey <- svydesign(ids = ~ 1 , data = br1 )", file = chapter.name , sep = "\n", append = TRUE) # cat("br2.survey <- svydesign(ids = ~ 1 , data = br2 )", file = chapter.name , sep = "\n", append = TRUE) + cat(paste0("\n```\n", sep = '\n'), file = chapter.name, append = TRUE) @@ -295,7 +318,7 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { ## Getting chapter questions ####### #chapterquestions <- dico[which(dico$chapter== chaptersname ), c("chapter", "name", "label", "type", "qrepeatlabel", "fullname","listname") ] chapterquestions <- dico[which(dico$chapter == chaptersname & dico$type %in% c("select_one","integer","select_multiple_d", "text","date", "numeric")), - c("chapter", "name", "label", "labelReport", "type", "qrepeatlabel", "fullname","listname","variable") ] + c("chapter", "name", "label", "labelReport","hintReport", "type", "qrepeatlabel", "fullname","listname","variable") ] #levels(as.factor(as.character(dico[which(!(is.na(dico$chapter)) & dico$formpart=="questions"), c("type") ]))) ##Loop.questions#################################################################################################### if (app == "shiny") { @@ -315,6 +338,7 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { questions.type <- as.character(chapterquestions[ j , c("type")]) questions.frame <- as.character(chapterquestions[ j , c("qrepeatlabel")]) questions.label <- as.character(chapterquestions[ j , c("labelReport")]) + questions.hint <- as.character(chapterquestions[ j , c("hintReport")]) questions.listname <- as.character(chapterquestions[ j , c("listname")]) questions.ordinal <- as.character(chapterquestions[ j , c("variable")]) if (is.na(questions.ordinal) ) {questions.ordinal <- "not.defined"} else {questions.ordinal <- questions.ordinal } @@ -328,9 +352,10 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { ## Now create para based on question type------- + cat(paste(questions.hint,"\n\n",sep = ""),file = chapter.name ,sep = "\n", append = TRUE) - ###selectone################################################################################################### + ###select one################################################################################################### if (questions.type == "select_one" ) { cat(paste("Single choice question ","\n\n",sep = ""),file = chapter.name ,sep = "\n", append = TRUE) @@ -342,17 +367,9 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { figheight <- as.integer(nrow(frequ)) if (figheight == 0) { figheight <- 1} else {figheight <- figheight/1.2} - cat(paste("### Tabulation" ,sep = ""),file = chapter.name ,sep = "\n", append = TRUE) - ## Open chunk - cat(paste0("```{r ", questions.name, ".tab, echo=FALSE, warning=FALSE, cache=FALSE, tidy = TRUE, message=FALSE, comment = \"\", fig.height=",figheight,", size=\"small\"}\n"), file = chapter.name, append = TRUE) - cat(paste("### Tabulation" ,sep = ""),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("##Compute contengency table"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("frequ <- as.data.frame(table(",questions.variable,"))"),file = chapter.name ,sep = "\n", append = TRUE) - #cat(paste0("if (nrow(frequ)==0){ cat(\"No response for this question\") } else{"),file = chapter.name ,sep = "\n", append = TRUE) - ## Check that there are responses to be displayed #### if (nrow(frequ) %in% c("0","1") ) { - cat(paste0("cat(\"No responses recorded for this question...\")"),file = chapter.name , sep = "\n", append = TRUE) + cat(paste0("cat(\"No responses or only one modality recorded for this question...\")"),file = chapter.name , sep = "\n", append = TRUE) cat("No responses recorded for this question...\n") # names(frequ)[2] <- "ccheck" @@ -360,9 +377,19 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { # } else if (sum(try) == 0) { # cat(paste0("cat(\"No responses recorded for this question...\")"),file = chapter.name , sep = "\n", append = TRUE) # cat("No responses recorded for this question...\n") - } else{ - cat(paste0("## display table"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("## Reorder factor"),file = chapter.name ,sep = "\n", append = TRUE) + } else { + + cat(paste("### Tabulation" ,sep = ""),file = chapter.name ,sep = "\n", append = TRUE) + ## Open chunk + cat(paste0("```{r ", questions.name, ".tab, echo=FALSE, warning=FALSE, cache=FALSE, tidy = TRUE, message=FALSE, comment = \"\", fig.height=",figheight,", size=\"small\"}\n"), file = chapter.name, append = TRUE) + cat(paste("### Tabulation" ,sep = ""),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("##Compute contengency table"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("frequ <- as.data.frame(table(",questions.variable,"))"),file = chapter.name ,sep = "\n", append = TRUE) + #cat(paste0("if (nrow(frequ)==0){ cat(\"No response for this question\") } else{"),file = chapter.name ,sep = "\n", append = TRUE) + + + # cat(paste0("## display table"),file = chapter.name ,sep = "\n", append = TRUE) + # cat(paste0("## Reorder factor"),file = chapter.name ,sep = "\n", append = TRUE) ## Check variable type to order the factor #### @@ -378,11 +405,11 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat(paste0("names(frequ)[1] <- \"", questions.shortname,"\""),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("kable(frequ, caption=\"__Table__:", questions.label,"\")"),file = chapter.name ,sep = "\n", append = TRUE) + # cat(paste0("kable(frequ, caption=\"__Table__:", questions.label,"\")"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("## Frequency table with NA in order to get non response rate"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("frequ1 <- as.data.frame(prop.table(table(", questions.variable,", useNA=\"ifany\")))"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("frequ1 <- as.data.frame(prop.table(table(", questions.variable,", useNA = \"ifany\")))"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("frequ1 <- frequ1[!(is.na(frequ1$Var1)), ]"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("frequ1 <- frequ1[!(frequ1$Var1==\"NA\"), ]"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("frequ1 <- frequ1[!(frequ1$Var1 == \"NA\"), ]"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("percentreponse <- paste0(round(sum(frequ1$Freq)*100,digits = 1),\"%\")"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("## Frequency table without NA"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("frequ2 <- as.data.frame(prop.table(table(", questions.variable,",useNA = \"no\")))"),file = chapter.name ,sep = "\n", append = TRUE) @@ -410,18 +437,19 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat(paste0("\n"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("## and now the graph"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("ggplot(frequ3, aes(x=frequ3$Var1, y=frequ3$mean)) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("geom_bar(fill=\"#2a87c8\",colour=\"#2a87c8\", stat =\"identity\", width=.8) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("guides(fill=FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("plot1 <- ggplot(frequ3, aes(x = frequ3$Var1, y = frequ3$mean)) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("geom_bar(fill = \"#2a87c8\", colour = \"#2a87c8\", stat = \"identity\", width=.8) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("guides(fill = FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("geom_label_repel(aes(y = mean, label = freqper2), fill = \"#2a87c8\", color = 'white') +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ylab(\"Frequency\") +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("scale_y_continuous(labels=percent) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("scale_y_continuous(labels = percent) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("xlab(\"\") +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("coord_flip() +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ggtitle(\"",questions.label,"\","),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("subtitle = paste0(\" Question response rate: \",percentreponse,\" .\")) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("theme(plot.title=element_text(face=\"bold\", size = 9 ),"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("plot.background = element_rect(fill = \"transparent\",colour = NA))"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("kobo_unhcr_style_bar()"),file = chapter.name ,sep = "\n", append = TRUE) + + cat(paste0("ggpubr::ggarrange(kobo_left_align(plot1, c(\"subtitle\", \"title\")), ncol = 1, nrow = 1)"),file = chapter.name ,sep = "\n", append = TRUE) } @@ -437,7 +465,7 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat("\n", file = chapter.name, append = TRUE) } else if (nrow(frequ) %in% c("0","1")) { # cat("No responses recorded for this question. No disaggregation...\n",file = chapter.name , sep = "\n", append = TRUE) - cat("No responses recorded for this question. No disaggregation...\n") + cat("No responses or only one modality recorded for this question. No disaggregation...\n") cat("\n", file = chapter.name, append = TRUE) } else { @@ -510,33 +538,33 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat(paste0("levels(",questions.frame,"$",disag.name,") <- list.ordinal"),file = chapter.name ,sep = "\n", append = TRUE) } else {} - cat(paste0("ggplot(",questions.frame,", aes(x=",questions.frame,"$",questions.name," , y=",questions.frame,"$",disag.name,")) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("plot1 <- ggplot(",questions.frame,", aes(x=",questions.frame,"$",questions.name," , y=",questions.frame,"$",disag.name,")) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("geom_boxplot(fill=\"#2a87c8\",colour=\"black\" ) + "),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("scale_size_area(max_size = 10) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("guides(fill=FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("guides(fill = FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("xlab(\"\") +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ylab(\"\") +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("coord_flip() +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("scale_y_continuous(breaks= pretty_breaks()) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("scale_y_continuous(breaks = pretty_breaks(), label = format_si()) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ggtitle(\"",questions.label,"\","),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("subtitle = \"Before data capping treatement. By question: ",disag.label,".\") +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("theme(plot.title=element_text(face=\"bold\", size = 9 ),plot.background = element_rect(fill = \"transparent\",colour = NA))"),file = chapter.name ,sep = "\n", append = TRUE) - + cat(paste0("kobo_unhcr_style_histo()"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("ggpubr::ggarrange(kobo_left_align(plot1, c(\"subtitle\", \"title\")), ncol = 1, nrow = 1)"),file = chapter.name ,sep = "\n", append = TRUE) ## Boxplot with capping treatment cat(paste0("## Boxplot"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("ggplot(",questions.frame,", aes(y=data.nooutlier1$variable, x= ",questions.frame,"$",questions.name,")) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("plot1 <- ggplot(",questions.frame,", aes(y=data.nooutlier1$variable, x= ",questions.frame,"$",questions.name,")) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("geom_boxplot(fill=\"#2a87c8\",colour=\"black\") + #notch=TRUE"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("scale_size_area(max_size = 10) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("guides(fill=FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("guides(fill = FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("xlab(\"\") +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ylab(\"\") +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("coord_flip() +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("scale_y_continuous(breaks= pretty_breaks()) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("scale_y_continuous(breaks = pretty_breaks(), label = format_si()) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ggtitle(\"",questions.label,"\","),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("subtitle = \"After data capping treatement. By question: ",disag.label,".\") +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("theme(plot.title=element_text(face=\"bold\", size = 9 ),"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("plot.background = element_rect(fill = \"transparent\",colour = NA))"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("kobo_unhcr_style_histo()"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("ggpubr::ggarrange(kobo_left_align(plot1, c(\"subtitle\", \"title\")), ncol = 1, nrow = 1)"),file = chapter.name ,sep = "\n", append = TRUE) ## Close chunk cat(paste0("\n```\n", sep = '\n'), file = chapter.name, append = TRUE) @@ -597,21 +625,23 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat(paste0("## and now the graph"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("ggplot(crosssfrequ.weight, aes(fill=crosssfrequ.weight$quest, y=crosssfrequ.weight$Freq, x = crosssfrequ.weight$disag)) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("plot1 <- ggplot(crosssfrequ.weight, aes(fill=crosssfrequ.weight$quest, y=crosssfrequ.weight$Freq, x = crosssfrequ.weight$disag)) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("geom_bar(colour=\"white\", stat =\"identity\", width=.8, aes(fill = quest), position = position_stack(reverse = TRUE)) +"),file = chapter.name ,sep = "\n", append = TRUE) #cat(paste0("geom_label_repel(aes(label = Freq2), fill = \"#2a87c8\", color = 'white') +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ylab(\"Frequency\") +"),file = chapter.name ,sep = "\n", append = TRUE) #cat(paste0("facet_wrap(~disag, ncol=3) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("scale_y_continuous(labels=percent) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("scale_y_continuous(labels = percent) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("scale_fill_viridis(discrete=TRUE) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("xlab(\"\") +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("coord_flip() +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ggtitle(\"",questions.label," (color)\","),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("subtitle = \" By question: ",disag.label," (bar)\") +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("theme(plot.title=element_text(face=\"bold\", size = 9 ),plot.background = element_rect(fill = \"transparent\",colour = NA)) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("kobo_unhcr_style_bar() +"),file = chapter.name ,sep = "\n", append = TRUE) ## setting up the legend - #cat(paste0("guides(fill=FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) + #cat(paste0("guides(fill = FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("theme(legend.direction = \"horizontal\", legend.position = \"bottom\", legend.box = \"horizontal\",legend.title=element_blank() )"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("ggpubr::ggarrange(kobo_left_align(plot1, c(\"subtitle\", \"title\")), ncol = 1, nrow = 1)"),file = chapter.name ,sep = "\n", append = TRUE) + ## Close chunk cat(paste0("\n```\n", sep = ""), file = chapter.name, append = TRUE) cat("\n", file = chapter.name, append = TRUE) @@ -684,7 +714,7 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { ## Check that each class is represented check.class <- as.data.frame(table(formula$target,formula$tested)) n.class <- nrow(check.class) - n.class.notnull <- nrow(check.class[check.class$Freq>0, ]) + n.class.notnull <- nrow(check.class[check.class$Freq > 0, ]) ### Testing number of levels for the 2 variables as 'x' and 'y' must have at least 2 levels if ( (chiquare.result[1, c("target")] != chiquare.result[1, c("tested")] ) & @@ -772,10 +802,10 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat(paste0("cat(\"No responses recorded for this question...\")"),file = chapter.name , sep = "\n", append = TRUE) cat("No responses recorded for this question...\n") } else if (nrow(frequ) > 10) { - cat(paste0("cat(\"There's too many potential values to display. We will only show the histogram. \n \")"),file = chapter.name ,sep = "\n", append = TRUE) + # cat(paste0("cat(\"There's too many potential values to display. We will only show the histogram. \n \")"),file = chapter.name ,sep = "\n", append = TRUE) } else{ - cat(paste0("## display table"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("kable(frequ, caption=\"__Table__:", questions.label,"\")"),file = chapter.name ,sep = "\n", append = TRUE) + # cat(paste0("## display table"),file = chapter.name ,sep = "\n", append = TRUE) + # cat(paste0("kable(frequ, caption=\"__Table__:", questions.label,"\")"),file = chapter.name ,sep = "\n", append = TRUE) } ## To do implement FD number of bin: https://www.r-bloggers.com/friday-function-nclass/ @@ -786,13 +816,13 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat(paste0("average <- as.data.frame(svymean(~ ",questions.name,", design = ",questions.frame,".survey, na.rm = TRUE))"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("cat(paste0(\"Based on the sample design, the average weighted mean response for this question is \", as.numeric(round(average$mean, digits = 2))))"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("# regular histogram"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("ggplot(data = frequ, aes(x = frequ$Var1, y = frequ$Freq)) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("plot1 <- ggplot(data = frequ, aes(x = frequ$Var1, y = frequ$Freq)) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("geom_bar(fill = \"#2a87c8\",colour = \"white\", stat = \"identity\", width = .8) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("labs(x = \"\", y = \"Count\") +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ggtitle(\"",questions.label,"\",subtitle = \"Before data capping treatement.\") +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0(""),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("kobo_unhcr_style_histo()"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("ggpubr::ggarrange(kobo_left_align(plot1, c(\"subtitle\", \"title\")), ncol = 1, nrow = 1)"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("theme(plot.title = element_text(face=\"bold\", size = 9 ), plot.background = element_rect(fill = \"transparent\",colour = NA))"),file = chapter.name ,sep = "\n", append = TRUE) ### Detect outliers and adjust bien numbers ##### ### To -- check there's outlier or not @@ -808,13 +838,13 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { ### Now graphs with treated variable ##### - cat(paste0("ggplot(data = data.nooutlier, aes(x = data.nooutlier$variable)) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("plot1 <- ggplot(data = data.nooutlier, aes(x = data.nooutlier$variable)) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("geom_histogram(color = \"white\",fill = \"#2a87c8\", breaks = pretty(data.nooutlier$variable, n = nclass.Sturges(data.nooutlier$variable),min.n = 1)) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("labs(x = \"\", y = \"Count\") +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ggtitle(\"",questions.label,"\","),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("subtitle = \"After data capping treatement.\") +"),file = chapter.name ,sep = "\n", append = TRUE) - - cat(paste0("theme(plot.title = element_text(face=\"bold\", size = 9), plot.background = element_rect(fill = \"transparent\",colour = NA))"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("kobo_unhcr_style_histo()"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("ggpubr::ggarrange(kobo_left_align(plot1, c(\"subtitle\", \"title\")), ncol = 1, nrow = 1)"),file = chapter.name ,sep = "\n", append = TRUE) } ## Close chunk cat(paste0("\n```\n", sep = '\n'), file = chapter.name, append = TRUE) @@ -889,34 +919,33 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { ## Boxplot - cat(paste0("ggplot(",questions.frame,", aes(y=",questions.frame,"$",questions.name," , x=",questions.frame,"$",disag.name,")) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("plot1 <- ggplot(",questions.frame,", aes(y=",questions.frame,"$",questions.name," , x=",questions.frame,"$",disag.name,")) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("geom_boxplot(fill=\"#2a87c8\",colour=\"black\") + "),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("scale_size_area(max_size = 10) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("guides(fill=FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("guides(fill = FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("xlab(\"\") +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ylab(\"\") +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("coord_flip() +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("scale_y_continuous(breaks= pretty_breaks()) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ggtitle(\"",questions.label,"\","),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("subtitle = \"Before data capping treatement, by question: ",disag.label,"\") +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("theme(plot.title=element_text(face=\"bold\", size = 9 ),"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("plot.background = element_rect(fill = \"transparent\",colour = NA))"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("kobo_unhcr_style_bar()"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("ggpubr::ggarrange(kobo_left_align(plot1, c(\"subtitle\", \"title\")), ncol = 1, nrow = 1)"),file = chapter.name ,sep = "\n", append = TRUE) ## Boxplot with capping treatment cat(paste0("## Boxplot"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("ggplot(",questions.frame,", aes(y=data.nooutlier$variable, x= ",questions.frame,"$",disag.name,")) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("plot1 <- ggplot(",questions.frame,", aes(y=data.nooutlier$variable, x= ",questions.frame,"$",disag.name,")) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("geom_boxplot(fill=\"#2a87c8\",colour=\"black\") + #notch=TRUE"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("scale_size_area(max_size = 10) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("guides(fill=FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("guides(fill = FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("xlab(\"\") +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ylab(\"\") +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("coord_flip() +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("scale_y_continuous(breaks= pretty_breaks()) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ggtitle(\"",questions.label,"\","),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("subtitle = \"After data capping treatement. By question: ",disag.label,"\") +"),file = chapter.name ,sep = "\n", append = TRUE) - - cat(paste0("theme(plot.title=element_text(face=\"bold\", size = 9 ),"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("plot.background = element_rect(fill = \"transparent\",colour = NA))"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("kobo_unhcr_style_bar()"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("ggpubr::ggarrange(kobo_left_align(plot1, c(\"subtitle\", \"title\")), ncol = 1, nrow = 1)"),file = chapter.name ,sep = "\n", append = TRUE) ## Close chunk cat(paste0("\n```\n", sep = '\n'), file = chapter.name, append = TRUE) @@ -940,30 +969,34 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat(paste0("names(data.nooutlier1)[1] <- \"variable\""),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("## Scatter plot"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("ggplot(",questions.frame,", aes(x= ",questions.frame,"$",disag.name, ", y=",questions.frame,"$",questions.name,")) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("plot1 <- ggplot(",questions.frame,", aes(x= ",questions.frame,"$",disag.name, ", y=",questions.frame,"$",questions.name,")) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("geom_count(aes(size = ..prop.., group = 1)) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("scale_size_area(max_size = 10) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("guides(fill=FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("guides(fill = FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("scale_y_continuous(breaks = pretty_breaks(), label = format_si()) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("scale_x_continuous(breaks = pretty_breaks(), label = format_si()) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("# xlab(correllabel) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("#ylab(variablelabel) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("# ylab(variablelabel) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("geom_smooth(method=lm) + # Add a loess smoothed fit curve with confidence region"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ggtitle(\"Scatterplot before data capping treatment\") +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("theme(plot.title=element_text(face=\"bold\", size = 9 ),"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("plot.background = element_rect(fill = \"transparent\",colour = NA))"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("kobo_unhcr_style_scatter()"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("ggpubr::ggarrange(kobo_left_align(plot1, c(\"subtitle\", \"title\")), ncol = 1, nrow = 1)"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("## Scatter plot rev "),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("ggplot(",questions.frame,", aes(x= data.nooutlier$variable, y=data.nooutlier1$variable )) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("plot1 <- ggplot(",questions.frame,", aes(x= data.nooutlier$variable, y=data.nooutlier1$variable )) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("geom_count(aes(size = ..prop.., group = 1)) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("scale_size_area(max_size = 10) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("guides(fill=FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("guides(fill = FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("scale_y_continuous(breaks = pretty_breaks(), label = format_si()) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("scale_x_continuous(breaks = pretty_breaks(), label = format_si()) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("# xlab(correllabel) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("#ylab(variablelabel) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("geom_smooth(method=lm) + # Add a loess smoothed fit curve with confidence region"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ggtitle(\"Scatterplot after data capping treatment\") +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("theme(plot.title=element_text(face=\"bold\", size = 9 ),"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("plot.background = element_rect(fill = \"transparent\",colour = NA))"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("kobo_unhcr_style_scatter()"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("ggpubr::ggarrange(kobo_left_align(plot1, c(\"subtitle\", \"title\")), ncol = 1, nrow = 1)"),file = chapter.name ,sep = "\n", append = TRUE) ## Close chunk cat(paste0("\n```\n", sep = '\n'), file = chapter.name, append = TRUE) @@ -1031,7 +1064,7 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat(paste0("check <- as.data.frame(names(",questions.frame ,"))"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("names(check)[1] <- \"check\""),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("check$id <- row.names(check)"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("check <- merge(x=check, y=selectmultilist1,by=\"check\")"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("check <- merge(x = check, y = selectmultilist1, by = \"check\")"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("selectmultilist <- as.character(check[ ,1])"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("## Reshape answers"),file = chapter.name ,sep = "\n", append = TRUE) @@ -1044,14 +1077,14 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat(paste0("castdata <- as.data.frame(table(meltdata[c(\"value\")]))"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("castdata$freqper <- castdata$Freq/nrow(data.selectmultilist)"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("castdata <- castdata[castdata$Var1!=\"Not selected\", ]"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("castdata$Var1 <-factor(castdata$Var1, levels=castdata[order(castdata$freqper), \"Var1\"])"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("castdata$Var1 <- factor(castdata$Var1, levels=castdata[order(castdata$freqper), \"Var1\"])"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("frequ <- castdata[castdata$Var1!=\"\", ]"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("## display table"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("names(frequ)[1] <- \"", questions.shortname,"\""),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("frequ[ ,3] <- paste0(round(frequ[ ,3]*100,digits = 1),\"%\")"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("kable(frequ, caption=\"__Table__:", questions.label,"\")"),file = chapter.name ,sep = "\n", append = TRUE) + # cat(paste0("kable(frequ, caption=\"__Table__:", questions.label,"\")"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("frequ1 <- castdata[castdata$Var1!=\"\", ]"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("frequ1[ ,4] <- paste0(round(frequ1[ ,3]*100,digits = 1),\"%\")"),file = chapter.name ,sep = "\n", append = TRUE) @@ -1060,18 +1093,18 @@ kobo_crunching_report <- function(form = "form.xls", app="console") { cat(paste0("\n"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("## and now the graph"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("ggplot(frequ1, aes(x=Var1, y=freqper)) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("geom_bar(fill=\"#2a87c8\",colour=\"#2a87c8\", stat =\"identity\", width=.8) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("guides(fill=FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("plot1 <- ggplot(frequ1, aes(x=Var1, y=freqper)) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("geom_bar(fill = \"#2a87c8\", colour = \"#2a87c8\", stat = \"identity\", width=.8) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("guides(fill = FALSE) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("geom_label_repel(aes(y = freqper, label = freqper2), fill = \"#2a87c8\", color = 'white') +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ylab(\"Frequency\") +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("scale_y_continuous(labels=percent) +"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("scale_y_continuous(labels = percent) +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("xlab(\"\") +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("coord_flip() +"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("ggtitle(\"",questions.label,"\","),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("subtitle = paste0(\"Question response rate: \",percentreponse,\" .\")) +"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("theme(plot.title=element_text(face=\"bold\", size = 9 ),"),file = chapter.name ,sep = "\n", append = TRUE) - cat(paste0("plot.background = element_rect(fill = \"transparent\",colour = NA))"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("kobo_unhcr_style_bar()"),file = chapter.name ,sep = "\n", append = TRUE) + cat(paste0("ggpubr::ggarrange(kobo_left_align(plot1, c(\"subtitle\", \"title\")), ncol = 1, nrow = 1)"),file = chapter.name ,sep = "\n", append = TRUE) cat(paste0("\n```\n", sep = '\n'), file = chapter.name, append = TRUE) ###select.multi.rel###################################################################### diff --git a/R/kobo_dico.R b/R/kobo_dico.R index 4cd88f9..abe8a85 100644 --- a/R/kobo_dico.R +++ b/R/kobo_dico.R @@ -39,6 +39,12 @@ kobo_dico <- function(form = "form.xls") { ## Rename the variable label names(survey)[names(survey) == "label::English"] <- "label" names(survey)[names(survey) == "label::english"] <- "label" + + + names(survey)[names(survey) == "hint::English"] <- "hint" + names(survey)[names(survey) == "hint::english"] <- "hint" + + cat("Checking now for additional information within your xlsform. Note that you can insert them in the xls and re-run the function! \n \n ") @@ -46,134 +52,142 @@ kobo_dico <- function(form = "form.xls") { ### add column if not present ################################################# if ("labelReport" %in% colnames(survey)) { - cat("1- Good: You have a column `labelReport` in your survey worksheet.\n"); + cat(" Good: You have a column `labelReport` in your survey worksheet.\n"); } else - {cat("1- No column `labelReport` in your survey worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `labelReport` in your survey worksheet. Creating a dummy one for the moment...\n"); survey[,"labelReport"] <- substr(survey[,"label"],1,80)} + + if ("hintReport" %in% colnames(survey)) + { + cat(" Good: You have a column `hintReport` in your survey worksheet.\n"); + } else + {cat(" No column `hintReport` in your survey worksheet. Creating a dummy one for the moment...\n"); + survey[,"hintReport"] <- survey[,"hint"]} + if ("disaggregation" %in% colnames(survey)) { - cat("1- Good: You have a column `disaggregation` in your survey worksheet.\n"); + cat(" Good: You have a column `disaggregation` in your survey worksheet.\n"); } else - {cat("1- No column `disaggregation` in your survey worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `disaggregation` in your survey worksheet. Creating a dummy one for the moment...\n"); survey$disaggregation <- ""} if ("correlate" %in% colnames(survey)) { - cat("2- Good: You have a column `correlate` in your survey worksheet. This will be used to define the variables that should be checked for correlation between each others.\n"); + cat(" Good: You have a column `correlate` in your survey worksheet. This will be used to define the variables that should be checked for correlation between each others.\n"); } else - {cat("2- No column `correlate` in your survey worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `correlate` in your survey worksheet. Creating a dummy one for the moment...\n"); survey$correlate <- ""} if ("chapter" %in% colnames(survey)) { - cat("3- Good: You have a column `chapter` in your survey worksheet. This will be used to breakdown the generated report\n"); + cat(" Good: You have a column `chapter` in your survey worksheet. This will be used to breakdown the generated report\n"); } else - {cat("3- No column `chapter` in your survey worksheet. Creating a dummy one for the moment ...\n"); + {cat(" No column `chapter` in your survey worksheet. Creating a dummy one for the moment ...\n"); survey$chapter <- ""} if ("structuralequation.risk" %in% colnames(survey)) { - cat("4- Good: You have a column `structuralequation.risk` in your survey worksheet. This will be used to configure the vulnerability structural equation model\n"); + cat(" Good: You have a column `structuralequation.risk` in your survey worksheet. This will be used to configure the vulnerability structural equation model\n"); } else - {cat("4- No column `structuralequation.risk` in your survey worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `structuralequation.risk` in your survey worksheet. Creating a dummy one for the moment...\n"); survey$structuralequation.risk <- ""} if ("structuralequation.coping" %in% colnames(survey)) { - cat("4- Good: You have a column `structuralequation.coping` in your survey worksheet. This will be used to configure the vulnerability structural equation model\n"); + cat(" Good: You have a column `structuralequation.coping` in your survey worksheet. This will be used to configure the vulnerability structural equation model\n"); } else {cat("4- No column `structuralequation.coping` in your survey worksheet. Creating a dummy one for the moment...\n"); survey$structuralequation.coping <- ""} if ("structuralequation.resilience" %in% colnames(survey)) { - cat("4- Good: You have a column `structuralequation.resilience` in your survey worksheet. This will be used to configure the vulnerability structural equation model\n"); + cat(" Good: You have a column `structuralequation.resilience` in your survey worksheet. This will be used to configure the vulnerability structural equation model\n"); } else - {cat("4- No column `structuralequation.resilience` in your survey worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `structuralequation.resilience` in your survey worksheet. Creating a dummy one for the moment...\n"); survey$structuralequation.resilience <- ""} if ("anonymise" %in% colnames(survey)) { - cat("5- Good: You have a column `anonymise` in your survey worksheet. This will be used to anonymise the dataset.\n"); + cat(" Good: You have a column `anonymise` in your survey worksheet. This will be used to anonymise the dataset.\n"); } else - {cat("5- No column `anonymise` in your survey worksheet. Creating a dummy one for the moment filled as `non-anonymised`. Other options to record are `Remove`, `Reference`, `Mask`, `Generalise` (see readme file) ...\n"); + {cat(" No column `anonymise` in your survey worksheet. Creating a dummy one for the moment filled as `non-anonymised`. Other options to record are `Remove`, `Reference`, `Mask`, `Generalise` (see readme file) ...\n"); survey$anonymise <- "default-non-anonymised"} if ("variable" %in% colnames(survey)) { - cat("6- Good: You have a column `variable` in your survey worksheet. This will be used to flag ordinal variable.\n"); + cat(" Good: You have a column `variable` in your survey worksheet. This will be used to flag ordinal variable.\n"); } else - {cat("6- No column `variable` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...\n"); + {cat(" No column `variable` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...\n"); survey$variable <- ""} ## Adding clean cluster predict if ("clean" %in% colnames(survey)) { - cat("7- Good: You have a column `clean` in your survey worksheet. This will be used to flag variables that shoudl be clean with kobo_clean function.\n"); + cat(" Good: You have a column `clean` in your survey worksheet. This will be used to flag variables that shoudl be clean with kobo_clean function.\n"); } else - {cat("7- No column `clean` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...\n"); + {cat(" No column `clean` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...\n"); survey$clean <- "no"} if ("cluster" %in% colnames(survey)) { - cat("8- Good: You have a column `cluster` in your survey worksheet. This will be used to flag variables to be used for clustering exploration.\n"); + cat(" Good: You have a column `cluster` in your survey worksheet. This will be used to flag variables to be used for clustering exploration.\n"); } else - {cat("8- No column `cluster` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...\n"); + {cat(" No column `cluster` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...\n"); survey$cluster <- ""} if ("predict" %in% colnames(survey)) { - cat("9- Good: You have a column `predict` in your survey worksheet. This will be used to flag variables to be used for clustering exploration.\n"); + cat(" Good: You have a column `predict` in your survey worksheet. This will be used to flag variables to be used for clustering exploration.\n"); } else - {cat("9- No column `predict` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...\n"); + {cat(" No column `predict` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...\n"); survey$predict <- ""} if ("mappoint" %in% colnames(survey)) { - cat("10- Good: You have a column `mappoint` in your survey worksheet. This will be used to flag variables to be used for clustering exploration.\n"); + cat(" Good: You have a column `mappoint` in your survey worksheet. This will be used to flag variables to be used for clustering exploration.\n"); } else - {cat("10- No column `mappoint` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...\n"); + {cat(" No column `mappoint` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...\n"); survey$mappoint <- ""} if ("mappoly" %in% colnames(survey)) { - cat("11- Good: You have a column `mappoly` in your survey worksheet. This will be used to flag variables to be used for clustering exploration.\n"); + cat(" Good: You have a column `mappoly` in your survey worksheet. This will be used to flag variables to be used for clustering exploration.\n"); } else - {cat("11- No column `mappoly` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...\n"); + {cat(" No column `mappoly` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...\n"); survey$mappoly <- ""} if ("relevant" %in% colnames(survey)) { - cat("1- Good: You have a column `relevant` in your survey worksheet.\n"); + cat(" Good: You have a column `relevant` in your survey worksheet.\n"); } else - {cat("1- No column `relevant` in your survey worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `relevant` in your survey worksheet. Creating a dummy one for the moment...\n"); survey[,"relevant"] <- ""} - + if ("required" %in% colnames(survey)) { - cat("1- Good: You have a column `required` in your survey worksheet.\n"); + cat(" Good: You have a column `required` in your survey worksheet.\n"); } else - {cat("1- No column `required` in your survey worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `required` in your survey worksheet. Creating a dummy one for the moment...\n"); survey[,"required"] <- ""} - + if ("constraint" %in% colnames(survey)) { - cat("1- Good: You have a column `constraint` in your survey worksheet.\n"); + cat(" Good: You have a column `constraint` in your survey worksheet.\n"); } else - {cat("1- No column `constraint` in your survey worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `constraint` in your survey worksheet. Creating a dummy one for the moment...\n"); survey[,"constraint"] <- ""} - + if ("repeat_count" %in% colnames(survey)) { - cat("1- Good: You have a column `repeat_count` in your survey worksheet.\n"); + cat(" Good: You have a column `repeat_count` in your survey worksheet.\n"); } else - {cat("1- No column `repeat_count` in your survey worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `repeat_count` in your survey worksheet. Creating a dummy one for the moment...\n"); survey[,"repeat_count"] <- ""} - + ## Avoid columns without names - survey <- survey[ ,c("type", "name" , "label", "labelReport", + survey <- survey[ ,c("type", "name" , "label", "labelReport", "hintReport", #"repeatsummarize", "variable","disaggregation", "chapter", "structuralequation.risk","structuralequation.coping","structuralequation.resilience", "anonymise","correlate","clean","cluster","predict","mappoint","mappoly", @@ -249,7 +263,9 @@ kobo_dico <- function(form = "form.xls") { } ### identify Repeat questions - survey$qrepeatlabel <- "MainDataFrame_edited" + + survey$qrepeatlabel <- "MainDataFrame" + nestable <- survey[survey$type %in% c("begin_repeat","begin repeat") , c("name","qrepeat","type")] nestable$name <- as.character(nestable$name) for (i in 2:nrow(survey)) @@ -259,7 +275,9 @@ kobo_dico <- function(form = "form.xls") { if ( survey[ i, c("type")] == "begin repeat" ) {survey[ i, c("qrepeatlabel")] <- survey[ i, c("name")]} else if ( survey[ i, c("type")] != "end repeat" && survey[ i - 1, c("qrepeat")] == "repeatnest1" ) {survey[ i, c("qrepeatlabel")] <- survey[ i - 1, c("qrepeatlabel")] } else if ( survey[ i, c("type")] != "end repeat" && survey[ i - 1, c("qrepeat")] == "repeatnest2" ) {survey[ i, c("qrepeatlabel")] <- survey[ i - 1, c("qrepeatlabel")] } - else if ( survey[ i, c("type")] == "end repeat" && survey[ i - 1, c("qrepeat")] == "repeatnest1") {survey[ i, c("qrepeatlabel")] <- "MainDataFrame_edited"} + + else if ( survey[ i, c("type")] == "end repeat" && survey[ i - 1, c("qrepeat")] == "repeatnest1") {survey[ i, c("qrepeatlabel")] <- "MainDataFrame"} + else if ( survey[ i, c("type")] == "end repeat" && survey[ i - 1, c("qrepeat")] == "repeatnest2") { nestabove <- as.character(survey[ i - 1, c("qrepeatlabel")]) nestabovenum <- as.integer(which(nestable$name == nestabove ) - 1) survey[ i, c("qrepeatlabel")] <- as.character( nestable[ nestabovenum , 1] ) } @@ -268,12 +286,16 @@ kobo_dico <- function(form = "form.xls") { else if ( survey[ i, c("type")] == "begin_repeat" ) {survey[ i, c("qrepeatlabel")] <- survey[ i, c("name")]} else if ( survey[ i, c("type")] != "end_repeat" && survey[ i - 1, c("qrepeat")] == "repeatnest1" ) {survey[ i, c("qrepeatlabel")] <- survey[ i - 1, c("qrepeatlabel")] } else if ( survey[ i, c("type")] != "end_repeat" && survey[ i - 1, c("qrepeat")] == "repeatnest2" ) {survey[ i, c("qrepeatlabel")] <- survey[ i - 1, c("qrepeatlabel")] } - else if ( survey[ i, c("type")] == "end_repeat" && survey[ i - 1, c("qrepeat")] == "repeatnest1") {survey[ i, c("qrepeatlabel")] <- "MainDataFrame_edited"} + + else if ( survey[ i, c("type")] == "end_repeat" && survey[ i - 1, c("qrepeat")] == "repeatnest1") {survey[ i, c("qrepeatlabel")] <- "MainDataFrame"} + else if ( survey[ i, c("type")] == "end_repeat" && survey[ i - 1, c("qrepeat")] == "repeatnest2") { nestabove <- as.character(survey[ i - 1, c("qrepeatlabel")]) nestabovenum <- as.integer(which(nestable$name == nestabove ) - 1) survey[ i, c("qrepeatlabel")] <- as.character( nestable[ nestabovenum , 1] ) } - else {survey[ i, c("qrepeatlabel")] <- "MainDataFrame_edited"} + + else {survey[ i, c("qrepeatlabel")] <- "MainDataFrame"} + } ### Get question levels in order to match the variable name @@ -400,41 +422,45 @@ kobo_dico <- function(form = "form.xls") { if ("labelReport" %in% colnames(choices)) { - cat("12 - Good: You have a column `labelReport` in your `choices` worksheet.\n"); + cat(" Good: You have a column `labelReport` in your `choices` worksheet.\n"); } else - {cat("12 - No column `labelReport` in your `choices` worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `labelReport` in your `choices` worksheet. Creating a dummy one for the moment...\n"); choices[,"labelReport"] <- substr(choices[,"label"],1,80)} if ("order" %in% colnames(choices)) { - cat("12 - Good: You have a column `order` in your `choices` worksheet.\n"); + cat(" Good: You have a column `order` in your `choices` worksheet.\n"); } else - {cat("12 - No column `order` in your `choices` worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `order` in your `choices` worksheet. Creating a dummy one for the moment...\n"); choices$order <- ""} if ("weight" %in% colnames(choices)) { - cat("13 - Good: You have a column `weight` in your `choices` worksheet.\n"); + cat(" Good: You have a column `weight` in your `choices` worksheet.\n"); } else - {cat("13 - No column `weight` in your `choices` worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `weight` in your `choices` worksheet. Creating a dummy one for the moment...\n"); choices$weight <- ""} if ("recategorise" %in% colnames(choices)) { - cat("14 - Good: You have a column `recategorise` in your `choices` worksheet.\n"); + cat(" Good: You have a column `recategorise` in your `choices` worksheet.\n"); } else - {cat("14 - No column `recategorise` in your `choices` worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `recategorise` in your `choices` worksheet. Creating a dummy one for the moment...\n"); choices$recategorise <- ""} if ("score" %in% colnames(choices)) { - cat("13 - Good: You have a column `score` in your `choices` worksheet.\n"); + cat(" Good: You have a column `score` in your `choices` worksheet.\n"); } else - {cat("13 - No column `score` in your `choices` worksheet. Creating a dummy one for the moment...\n"); + {cat(" No column `score` in your `choices` worksheet. Creating a dummy one for the moment...\n"); choices$score <- ""} choices <- choices[,c("listname", "name", "labelReport", "order", "weight","score","recategorise")] + + + + names(choices)[names(choices) == "labelReport"] <- "labelchoice" #rm(choices) choices <- join(x = choices, y = survey, by = "listname", type = "left") @@ -458,7 +484,7 @@ kobo_dico <- function(form = "form.xls") { #names(choices) -"type", "name", "namefull", "labelfull", "listname", "qrepeat", "qlevel", "qgroup" ## not kept: "nameq" "labelq" ,"fullname", "label", #names(survey) - "type" "name", "fullname", "label", "listname", "qrepeat"m "qlevel", "qgroup" - choices2 <- choices[ ,c("type", "name", "namefull", "labelfull", "labelReport", "chapter","disaggregation","correlate", "structuralequation.risk","structuralequation.coping","structuralequation.resilience","anonymise", + choices2 <- choices[ ,c("type", "name", "namefull", "labelfull", "labelReport","hintReport", "chapter","disaggregation","correlate", "structuralequation.risk","structuralequation.coping","structuralequation.resilience","anonymise", "clean","cluster","predict","mappoint","mappoly", "relevant", "required", "constraint", "repeat_count", "listname", "qrepeat","qrepeatlabel", "qlevel", "qgroup", "labelchoice", @@ -472,7 +498,7 @@ kobo_dico <- function(form = "form.xls") { names(choices2)[names(choices2) == "labelfull"] <- "label" - survey2 <- survey[,c("type", "name", "fullname", "label", "labelReport", "chapter", "disaggregation","correlate", "structuralequation.risk","structuralequation.coping","structuralequation.resilience","anonymise", + survey2 <- survey[,c("type", "name", "fullname", "label", "labelReport","hintReport", "chapter", "disaggregation","correlate", "structuralequation.risk","structuralequation.coping","structuralequation.resilience","anonymise", "clean","cluster","predict","mappoint","mappoly", "relevant", "required", "constraint", "repeat_count", "listname", "qrepeat","qrepeatlabel", "qlevel", "qgroup", "labelchoice", diff --git a/R/kobo_dummy.R b/R/kobo_dummy.R index 1309140..9c1ed1c 100644 --- a/R/kobo_dummy.R +++ b/R/kobo_dummy.R @@ -33,9 +33,9 @@ kobo_dummy <- function(form = "form.xls") { - ### Write dummy dataset - + samplesize <- 381 + ### Write dummy dataset #kobodevtools::install_github("ropensci/charlatan") #devtools::install_github("ThinkR-open/fakir") # install.packages("truncnorm") @@ -181,7 +181,7 @@ kobo_dummy <- function(form = "form.xls") { ## Create corresponding dummy data ######## - samplesize <- 500 + ## generate the unique ID for each observation dummydata <- data.frame(stri_rand_strings(samplesize, 8)) @@ -321,12 +321,12 @@ kobo_dummy <- function(form = "form.xls") { #levels(as.factor(as.character(dico.repeat$type))) for (h in 1:length(repeat_name)) { - # h <-2 + # h <- 2 repeat_table <- as.character(repeat_name[h]) ## Build corresponding repeat frame dico.repeat1 <- dico.repeat[dico.repeat$qrepeatlabel == repeat_table, ] - ## Getting records to be generated for each ID + cat("Getting records to be generated for each ID \n\n\n") maxvariable <- as.character(dico[dico$qrepeatlabel == repeat_table & dico$type %in% c("begin_repeat", "begin repeat") , c("repeat_count") ]) @@ -335,140 +335,152 @@ kobo_dummy <- function(form = "form.xls") { maxvariablefullname <- maxvariablefullname[!(is.na(maxvariablefullname$fullname)), c("fullname")] maxvariablefullname <- as.character(maxvariablefullname) #str(maxvariablefullname) - + rm(dummydatamaxvariable) dummydatamaxvariable <- dummydata[ ,c("instanceID",maxvariablefullname )] #str(dummydatamaxvariable) ## Account for NA - relevant nested table dummydatamaxvariable <- dummydatamaxvariable[ !(is.na(dummydatamaxvariable[ ,2])), ] - - - # names(dummydata) - + # names(dummydata) #dummydatarepeat <- data.frame("instanceID" ) #names(dummydatarepeat)[1] <- "instanceID" dummydatarepeatall <- as.data.frame(matrix(0, ncol = 1 + nrow(dico.repeat1), nrow = 0)) names(dummydatarepeatall)[1] <- "instanceID" names(dummydatarepeatall)[2:(nrow(dico.repeat1) + 1)] <- as.character(dico.repeat1[ ,c("fullname")]) - ## Loop around IDs - for (j in 1:nrow(dummydatamaxvariable) ) { - # j <- 1 - samplesize <- as.numeric(dummydatamaxvariable[ j, 2]) - this.id <- as.character(dummydatamaxvariable[ j, 1]) - - dummydatarepeat <- as.data.frame(matrix(0, ncol = 1, nrow = samplesize)) - dummydatarepeat[1] <- this.id - names(dummydatarepeat)[1] <- "instanceID" - - ## Loop around variables - for (i in 1:nrow(dico.repeat1) ) { - # i <- 46 - fullname <- as.character(dico.repeat1[i, c("fullname")]) - typedata <- as.character(dico.repeat1[dico.repeat1$fullname == fullname, c("type")]) - - - relevantifvar <- as.character(dico.repeat1[dico.repeat1$fullname == fullname, c("relevantifvar")]) - relevantifvar2 <- as.character(dico.repeat1[dico.repeat1$name == relevantifvar, c("fullname")]) - relevantifvalue <- as.character(dico.repeat1[dico.repeat1$fullname == fullname, c("relevantifvalue")]) - - cat(paste0("Entering dummy data for nested table ", h, " - ", repeat_table, - "for case ", j, - " for variable ", i, "- ", fullname, " / ", typedata,"\n")) - if (typedata %in% c("date") ) { - dummydatarepeat[ , i + 1] <- sample(seq(as.Date('2017/01/01'), as.Date('2019/01/01'), by = "day"), - replace = TRUE, - size = samplesize) - } - - if (typedata == "select_one") { - listname <- as.character(dico[dico$fullname == fullname & - dico$type == "select_one", c("listname")]) - categ_level <- as.character( unique(dico[dico$listname == listname & - dico$type == "select_one_d", c("name")])) - dummydatarepeat[ , i + 1] <- factor(sample(categ_level, - size = samplesize, - replace = TRUE)) - } - if (typedata == "select_multiple_d") { - listname <- as.character(dico[dico$fullname == fullname & - dico$type == "select_multiple_d", c("listname")]) - categ_level <- as.character( unique(dico[dico$listname == listname & - dico$type == "select_multiple", c("name")])) - dummydatarepeat[ , i + 1] <- factor(sample(categ_level, - size = samplesize, - replace = TRUE)) - } - if (typedata == "integer") { - lowerbound <- ifelse( is.na(as.numeric(dico.repeat1[ i, c("lowerbound")])), 0, as.numeric(dico.repeat1[ i, c("lowerbound")])) - upperbound <- ifelse(is.na(as.numeric(dico.repeat1[ i, c("upperbound")])), 100, as.numeric(dico.repeat1[ i, c("upperbound")])) - dummydatarepeat[ , i + 1] <- round(rtruncnorm(n = samplesize, - a = lowerbound, #lowerbound, # vector of lower bounds. These may be -Inf - b = upperbound, # vector of upper bounds. These may be Inf - mean = ((upperbound - lowerbound ) / 2), # vector of means. - sd = ((upperbound - lowerbound ) / 4) # vector of standard deviations. - )) - } - if (typedata == "calculate") { - lowerbound <- ifelse( is.na(as.numeric(dico.repeat1[ i, c("lowerbound")])), 0, as.numeric(dico.repeat1[ i, c("lowerbound")])) - upperbound <- ifelse(is.na(as.numeric(dico.repeat1[ i, c("upperbound")])), 100, as.numeric(dico.repeat1[ i, c("upperbound")])) - dummydatarepeat[ , i + 1] <- round(rtruncnorm(n = samplesize, - a = lowerbound, #lowerbound, # vector of lower bounds. These may be -Inf - b = upperbound, # vector of upper bounds. These may be Inf - mean = ((upperbound - lowerbound ) / 2), # vector of means. - sd = ((upperbound - lowerbound ) / 4) # vector of standard deviations. - )) - } - if (typedata == "decimal") { - lowerbound <- ifelse( is.na(as.numeric(dico.repeat1[ i, c("lowerbound")])), 0, as.numeric(dico.repeat1[ i, c("lowerbound")])) - upperbound <- ifelse(is.na(as.numeric(dico.repeat1[ i, c("upperbound")])), 100, as.numeric(dico.repeat1[ i, c("upperbound")])) - dummydatarepeat[ , i + 1] <- rtruncnorm(n = samplesize, - a = lowerbound, #lowerbound, # vector of lower bounds. These may be -Inf - b = upperbound, # vector of upper bounds. These may be Inf - mean = ((upperbound - lowerbound ) / 2), # vector of means. - sd = ((upperbound - lowerbound ) / 4) # vector of standard deviations. - ) - } - - if (typedata == "text") { - #dummydatarepeat[ , i + 1] <- "this is a dummy text" - dummydatarepeat[ , i + 1] <- randomSentences(n = samplesize, 3:10) - } - - ## Then rename correctly - names(dummydatarepeat)[i + 1 ] <- fullname - #cat(summary(dummydatarepeat[i])) + # if ( nrow(dico.repeat1) == 1) { + # ## only one variable linked on the second table + # + # + # } else { + + + ## Loop around IDs for each case + for (j in 1:nrow(dummydatamaxvariable) ) { + # j <- 1 + samplesize <- as.numeric(dummydatamaxvariable[ j, 2]) + + if (samplesize !=0 ) { + this.id <- as.character(dummydatamaxvariable[ j, 1]) + + dummydatarepeat <- as.data.frame(matrix(0, ncol = 1, nrow = samplesize)) + dummydatarepeat[1] <- this.id + names(dummydatarepeat)[1] <- "instanceID" + + + + ## Loop around variables + for (i in 1:nrow(dico.repeat1) ) { + # i <- 1 + fullname <- as.character(dico.repeat1[i, c("fullname")]) + typedata <- as.character(dico.repeat1[dico.repeat1$fullname == fullname, c("type")]) + + + relevantifvar <- as.character(dico.repeat1[dico.repeat1$fullname == fullname, c("relevantifvar")]) + relevantifvar2 <- as.character(dico.repeat1[dico.repeat1$name == relevantifvar, c("fullname")]) + relevantifvalue <- as.character(dico.repeat1[dico.repeat1$fullname == fullname, c("relevantifvalue")]) + + cat(paste0("Entering dummy data for nested table ", h, " - ", repeat_table, + "for case ", j, + " for variable ", i, "- ", fullname, " / ", typedata,"\n")) + if (typedata %in% c("date") ) { + dummydatarepeat[ , i + 1] <- sample(seq(as.Date('2017/01/01'), as.Date('2019/01/01'), by = "day"), + replace = TRUE, + size = samplesize) + } + + if (typedata == "select_one") { + listname <- as.character(dico[dico$fullname == fullname & + dico$type == "select_one", c("listname")]) + categ_level <- as.character( unique(dico[dico$listname == listname & + dico$type == "select_one_d", c("name")])) + dummydatarepeat[ , i + 1] <- factor(sample(categ_level, + size = samplesize, + replace = TRUE)) + } + if (typedata == "select_multiple_d") { + listname <- as.character(dico[dico$fullname == fullname & + dico$type == "select_multiple_d", c("listname")]) + categ_level <- as.character( unique(dico[dico$listname == listname & + dico$type == "select_multiple", c("name")])) + dummydatarepeat[ , i + 1] <- factor(sample(categ_level, + size = samplesize, + replace = TRUE)) + } + if (typedata == "integer") { + lowerbound <- ifelse( is.na(as.numeric(dico.repeat1[ i, c("lowerbound")])), 0, as.numeric(dico.repeat1[ i, c("lowerbound")])) + upperbound <- ifelse(is.na(as.numeric(dico.repeat1[ i, c("upperbound")])), 100, as.numeric(dico.repeat1[ i, c("upperbound")])) + dummydatarepeat[ , i + 1] <- round(rtruncnorm(n = samplesize, + a = lowerbound, #lowerbound, # vector of lower bounds. These may be -Inf + b = upperbound, # vector of upper bounds. These may be Inf + mean = ((upperbound - lowerbound ) / 2), # vector of means. + sd = ((upperbound - lowerbound ) / 4) # vector of standard deviations. + )) + } + if (typedata == "calculate") { + lowerbound <- ifelse( is.na(as.numeric(dico.repeat1[ i, c("lowerbound")])), 0, as.numeric(dico.repeat1[ i, c("lowerbound")])) + upperbound <- ifelse(is.na(as.numeric(dico.repeat1[ i, c("upperbound")])), 100, as.numeric(dico.repeat1[ i, c("upperbound")])) + dummydatarepeat[ , i + 1] <- round(rtruncnorm(n = samplesize, + a = lowerbound, #lowerbound, # vector of lower bounds. These may be -Inf + b = upperbound, # vector of upper bounds. These may be Inf + mean = ((upperbound - lowerbound ) / 2), # vector of means. + sd = ((upperbound - lowerbound ) / 4) # vector of standard deviations. + )) + } + if (typedata == "decimal") { + lowerbound <- ifelse( is.na(as.numeric(dico.repeat1[ i, c("lowerbound")])), 0, as.numeric(dico.repeat1[ i, c("lowerbound")])) + upperbound <- ifelse(is.na(as.numeric(dico.repeat1[ i, c("upperbound")])), 100, as.numeric(dico.repeat1[ i, c("upperbound")])) + dummydatarepeat[ , i + 1] <- rtruncnorm(n = samplesize, + a = lowerbound, #lowerbound, # vector of lower bounds. These may be -Inf + b = upperbound, # vector of upper bounds. These may be Inf + mean = ((upperbound - lowerbound ) / 2), # vector of means. + sd = ((upperbound - lowerbound ) / 4) # vector of standard deviations. + ) + } + + if (typedata == "text") { + #dummydatarepeat[ , i + 1] <- "this is a dummy text" + dummydatarepeat[ , i + 1] <- randomSentences(n = samplesize, 3:10) + } + + ## Then rename correctly + names(dummydatarepeat)[i + 1 ] <- fullname + #cat(summary(dummydatarepeat[i])) + + + ## Put to NA if relevance condition is set and not respected + if ( !(is.na(relevantifvar)) & relevantifvar != "" ) { + datacheck <- as.data.frame(dummydatarepeat[ , c(relevantifvar2) ]) + cat(paste0(" Apply relevance on ",relevantifvar2," \n")) + for (l in 1:nrow(dummydatarepeat)) { + # l <- 3 + + value <- ifelse(is.na(datacheck[l,]),"", + ifelse(datacheck[l,] == relevantifvalue , paste(dummydatarepeat[l ,i + 1 ]), "")) + if (value == "") { + dummydatarepeat[l ,i + 1 ] <- NA } else { + dummydatarepeat[l ,i + 1 ] <- value + } + #dummydatarepeat[l ,i + 1 ] <- ifelse(datacheck[l,] == relevantifvalue , paste(dummydatarepeat[l ,i + 1 ]), "") + } + } - ## Put to NA if relevance condition is set and not respected - if ( !(is.na(relevantifvar)) & relevantifvar != "" ) { - datacheck <- as.data.frame(dummydatarepeat[ , c(relevantifvar2) ]) - cat(paste0(" Apply relevance on ",relevantifvar2," \n")) - for (l in 1:nrow(dummydatarepeat)) { - # l <- 3 - value <- ifelse(is.na(datacheck[l,]),"", - ifelse(datacheck[l,] == relevantifvalue , paste(dummydatarepeat[l ,i + 1 ]), "")) - if (value == "") { - dummydatarepeat[l ,i + 1 ] <- NA } else { - dummydatarepeat[l ,i + 1 ] <- value - } - #dummydatarepeat[l ,i + 1 ] <- ifelse(datacheck[l,] == relevantifvalue , paste(dummydatarepeat[l ,i + 1 ]), "") + } + cat("Appending this record \n\n") + dummydatarepeatall <- rbind(dummydatarepeatall, dummydatarepeat) + rm(dummydatarepeat) } } - - - } - dummydatarepeatall <- rbind(dummydatarepeatall, dummydatarepeat) - rm(dummydatarepeat) - - } + # } write.csv(dummydatarepeatall, paste0("data/",repeat_table,".csv"), row.names = FALSE) cat(paste0("\n\n\n Finished generation of nested table ", h, " - ", repeat_table, "\n")) rm(dummydatarepeatall) + } -} + } NULL diff --git a/R/kobo_get_theme.R b/R/kobo_get_theme.R index 7efb515..17f1572 100644 --- a/R/kobo_get_theme.R +++ b/R/kobo_get_theme.R @@ -28,7 +28,7 @@ #' @export kobo_get_theme #' -kobo_get_theme <- function(form = "form.xls") { +kobo_get_theme <- function() { themeList <- list() diff --git a/R/kobo_left_align.R b/R/kobo_left_align.R new file mode 100644 index 0000000..37022fb --- /dev/null +++ b/R/kobo_left_align.R @@ -0,0 +1,22 @@ +#' @name kobo_left_align +#' @rdname kobo_left_align +#' @title UNHCR ggplot2 theme +#' +#' @description Left align chart title and subtitle on a ggplot2 +#' +#' @return Return better chart +#' +#' @author Edouard Legoupil - with inspiration from bbc +#' +#' @examples +#' kobo_left_align() +#' +#' @export kobo_left_align +#' + +kobo_left_align <- function(plot_name, pieces){ + grob <- ggplot2::ggplotGrob(plot_name) + n <- length(pieces) + grob$layout$l[grob$layout$name %in% pieces] <- 2 + return(grob) +} diff --git a/R/kobo_load_data.R b/R/kobo_load_data.R index f63a235..0a48be1 100644 --- a/R/kobo_load_data.R +++ b/R/kobo_load_data.R @@ -6,7 +6,7 @@ #' #' @param form The full filename of the form to be accessed (xls or xlsx file). #' It is assumed that the form is stored in the data folder. -#' +#' #' @param app The place where the function has been executed, the default is the console and the second option is the shiny app #' #' @return No return, all results will be saved inside new CSV files @@ -24,10 +24,11 @@ #' @export kobo_load_data #' -kobo_load_data <- function(form = "form.xls", app="console") { - tryCatch({ +kobo_load_data <- function(form = "form.xls", app = "console") { + tryCatch ( { ## Load all required packages############################################# - if(app=="shiny"){ + + if (app == "shiny") { progress <- shiny::Progress$new() progress$set(message = "Load Data in progress...", value = 0) on.exit(progress$close()) @@ -40,56 +41,90 @@ kobo_load_data <- function(form = "form.xls", app="console") { } updateProgress() } + + kobo_load_packages() + + ## getting project configuration variables + cat("\n\n\n Getting project configuration variables \n\n\n\n") configInfoOrigin <- kobo_get_config(form) configInfoOrigin <- configInfoOrigin[!is.na(configInfoOrigin$name),] - mainDir <- kobo_getMainDirectory() - + + + cat("\n\n\n Generate dictionnary from the xlsform \n\n\n\n") + mainDir <- kobo_getMainDirectory() kobo_dico(form) dico <- read.csv(paste0(mainDir,"/data/dico_",form,".csv"), encoding = "UTF-8", na.strings = "") - + ## Load data ####################################################################### cat("\n\n\n Load original dataset \n\n\n\n") - originalData <- read.csv(configInfoOrigin[configInfoOrigin$name=="MainDataFrame", "path"], sep = ",", encoding = "UTF-8", na.strings = "") - + + originalData <- read.csv(configInfoOrigin[configInfoOrigin$name == "MainDataFrame", "path"], sep = ",", encoding = "UTF-8", na.strings = "") + + if (ncol(originalData) == 1) { + cat("seems like you file use ; rather , variable separator.... \n") + originalData <- read.csv(configInfoOrigin[configInfoOrigin$name == "MainDataFrame", "path"], sep = ";", encoding = "UTF-8", na.strings = "") + } + ## Check to split select_multiple if data is extracted from ODK ################### - cat("\n\n\n Now split select_multiple variables \n\n\n\n") - if(app=="shiny"){ + if (app == "shiny") { progress$set(message = "Splitting Main Data File in progress...") updateProgress() } - MainDataFrame_edited <- kobo_split_multiple(originalData, dico) - + + cat("\n\n\n Now split select_multiple variables \n\n\n\n") + MainDataFrame <- kobo_split_multiple(originalData, dico) + + ## Clean variable if any ########################################################## - cat("\n\n\n Clean variable if any \n\n\n\n") - if(app=="shiny"){ + if (app == "shiny") { progress$set(message = "Cleaning Main Data File in progress...") updateProgress() } - MainDataFrame_edited <- kobo_clean(MainDataFrame_edited, dico) + + + cat("\n\n\n Clean variable if any \n\n\n\n") + MainDataFrame <- kobo_clean(MainDataFrame, dico) + + ## Join with Weight file ######################################### - cat("\n\n\n Adding weight and removing some forms \n\n\n\n") - if(nrow(configInfoOrigin)==0){ - cat("\n\n\n You need to enter the sampling methods and all required parameters in settings sheet before processed \n\n\n\n") + cat("\n\n\n Set up sampling \n\n\n\n") + + if (nrow(configInfoOrigin) == 0) { + cat("\n\n\n You need to enter the sampling methods and all required parameters in settings sheet before processed \n\n No sampling(type 1) \n\n Cluster sample (type 2) \n\n Stratified sample (type 3) \n\n") return(FALSE) } - if(length(configInfoOrigin[configInfoOrigin$name=="sample_type", "value"])!=0){ - if(configInfoOrigin[configInfoOrigin$name=="sample_type", "value"] != "No sampling(type 1)"){ - if(app=="shiny"){ + + if (length(configInfoOrigin[configInfoOrigin$name == "sample_type", "value"]) != 0) { + + if (configInfoOrigin[configInfoOrigin$name == "sample_type", "value"] != "No sampling (type 1)") { + + if (app == "shiny") { progress$set(message = "Adding weights with Main Data File in progress...") updateProgress() } - path <- configInfoOrigin[configInfoOrigin$name=="weights_info", "path"] + + path <- configInfoOrigin[configInfoOrigin$name == "weights_info", "path"] weight <- read.csv(path,stringsAsFactors = F) - variableName <- configInfoOrigin[configInfoOrigin$name=="variable_name", "value"] - MainDataFrame_edited <- left_join(x = MainDataFrame_edited, y = weight, by = variableName) + + + variableName <- configInfoOrigin[configInfoOrigin$name == "variable_name", "value"] + MainDataFrame <- left_join(x = MainDataFrame, y = weight, by = variableName) + + } } + + ## Cheking the labels matching... ################################################# - ## MainDataFrame_edited is the default root data componnents to be used -- in order to deal with nested dataset - if(app=="shiny"){ + + + ## MainDataFrame is the default root data componnents to be used -- in order to deal with nested dataset + if (app == "shiny") { + + progress$set(message = "labeling variables for Main Data File in progress...") updateProgress() } @@ -97,144 +132,198 @@ kobo_load_data <- function(form = "form.xls", app="console") { MainDataFrame_edited <- kobo_label(MainDataFrame_edited, dico) ## Save preliminary version before encoding or adding indicators ################## - cat("\n\nWrite backup before encoding or indicators calculation..\n") - write.csv(MainDataFrame_edited,paste(mainDir,"/data/MainDataFrame_edited.csv",sep = ""), row.names = FALSE, na = "") - + + + cat("\n\n Write backup before encoding or indicators calculation..\n") + write.csv(MainDataFrame,paste(mainDir,"/data/MainDataFrame-edited.csv",sep = ""), row.names = FALSE, na = "") + + + ## load all required data files ######################################### - cat("\n\nload all required data files..\n") - if(app=="shiny"){ + cat("\n\nload all required nested data files..\n") + if (app == "shiny") { progress$set(message = "loading all required data files in progress...") updateProgress() } - + + configInfo <- configInfoOrigin[startsWith(tolower(configInfoOrigin$name), "instanceid"),] + levelsOfDF <- kobo_get_dataframes_levels(form) - levelsOfDF <- levelsOfDF[levelsOfDF$name!="MainDataFrame",] - if(nrow(levelsOfDF)!=0){ - levelsOfDF[levelsOfDF$parent=="MainDataFrame","parent"] <- "MainDataFrame_edited" - } - #ataBeginRepeat <- kobo_get_begin_repeat("form2.xls") + + + levelsOfDF <- levelsOfDF[levelsOfDF$name != "MainDataFrame",] + if (nrow(levelsOfDF) != 0) { + # levelsOfDF[levelsOfDF$parent == "MainDataFrame","parent"] <- "MainDataFrame" + #} + #dataBeginRepeat <- kobo_get_begin_repeat("form2.xls") + + #dataBeginRepeat <- dataBeginRepeat$names - - if(nrow(levelsOfDF)!=0){ - + + for (dbr in levelsOfDF$name) { - cat("\n\nload all required data files..\n") - if(app=="shiny"){ + + if (app == "shiny") { progress$set(message = paste("loading",dbr,"file in progress...")) updateProgress() } - - dataFrame <- read.csv(configInfoOrigin[configInfoOrigin$name==dbr,"path"], stringsAsFactors = F) - - if(app=="shiny"){ + # dbr <- levelsOfDF$name[1] + cat("\n\nloading",dbr,"file ..\n") + dataFrame <- read.csv(configInfoOrigin[configInfoOrigin$name == dbr,"path"], stringsAsFactors = F) + + if (app == "shiny") { progress$set(message = paste("Splitting",dbr,"file in progress...")) updateProgress() } + cat(paste("Splitting",dbr,"file in progress...\n")) dataFrame <- kobo_split_multiple(dataFrame, dico) - if(app=="shiny"){ + + + if (app == "shiny") { progress$set(message = paste("Cleaning",dbr,"file in progress...")) updateProgress() } + cat(paste("Cleaning",dbr,"file in progress...\n")) dataFrame <- kobo_clean(dataFrame, dico) - if(app=="shiny"){ + + + if (app == "shiny") { progress$set(message = paste("Labeling",dbr,"file in progress...")) updateProgress() } + cat(paste("Labeling",dbr,"file in progress...\n")) dataFrame <- kobo_label(dataFrame, dico) - - write.csv(dataFrame,paste(mainDir,"/data/",dbr,"_edited.csv",sep = ""), row.names = FALSE, na = "") - cat("\n\nload",dbr,"and create all needed files for it..\n") - - } - for (dbr in levelsOfDF$name) { - if(app=="shiny"){ - progress$set(message = paste("loading",dbr,"file in progress...")) - updateProgress() - } - dataFrame <- read.csv(paste(mainDir,"/data/",dbr,"_edited.csv",sep = ""),stringsAsFactors = F) - child <- levelsOfDF[levelsOfDF$name==dbr, "name"] - parent <- levelsOfDF[levelsOfDF$name==dbr, "parent"] + + + cat("\n\n Saving ",dbr,"file as -edited..\n") + write.csv(dataFrame,paste(mainDir,"/data/",dbr,"-edited.csv",sep = ""), row.names = FALSE, na = "") + + # } + # + # + # cat("\n\n Join hierarchical structured if defined..\n") + # for (dbr in levelsOfDF$name) { + + # if (app == "shiny") { + # progress$set(message = paste("loading",dbr,"file in progress...")) + # updateProgress() + # } + # + # dataFrame <- read.csv(paste(mainDir,"/data/",dbr,"-edited.csv",sep = ""),stringsAsFactors = F) + child <- levelsOfDF[levelsOfDF$name == dbr, "name"] + parent <- levelsOfDF[levelsOfDF$name == dbr, "parent"] + + cat("\n\n Join hierarchical structure between ", child, " and ", parent, " in order to calculate indicators...\n") + while (T) { - instanceIDChild <- configInfo[tolower(configInfo$name)==tolower(paste0("instanceid_",child,"_",ifelse(parent=="MainDataFrame_edited","MainDataFrame",parent))), "value"] - instanceIDParent <- configInfo[tolower(configInfo$name)==tolower(paste0("instanceid_",ifelse(parent=="MainDataFrame_edited","MainDataFrame",parent),"_",child)), "value"] - if(parent=="MainDataFrame_edited"){ - parentDf <- read.csv(paste(mainDir,"/data/",parent,".csv",sep = ""),stringsAsFactors = F) + instanceIDChild <- configInfo[tolower(configInfo$name) == tolower(paste0("instanceid_",child,"_",ifelse(parent == "household","MainDataFrame",parent))), "value"] + instanceIDParent <- configInfo[tolower(configInfo$name) == tolower(paste0("instanceid_",ifelse(parent == "household","MainDataFrame",parent),"_",child)), "value"] + + ## Case MainDataFrame called household + if (parent %in% c("household", "MainDataFrame")) { + parentDf <- read.csv(paste(mainDir,"/data/",parent,"-edited.csv",sep = ""),stringsAsFactors = F) + }else{ parentDf <- read.csv(paste(mainDir,"/data/",parent,"_edited.csv",sep = ""),stringsAsFactors = F) } + + + ## Preparing the 2 data frame for a left join - create a common key betwee 2 frames for the left_join unColChild <- dataFrame[,instanceIDChild] - dataFrame <- dataFrame[colnames(dataFrame)!=instanceIDChild] + + ## Removing this from child + dataFrame <- dataFrame[ colnames(dataFrame) != instanceIDChild] + + ## get all variables from child that are not in parent + unCN <- colnames(dataFrame)[!colnames(dataFrame) %in% colnames(parentDf)] - - if(instanceIDChild != instanceIDParent){ + + if (instanceIDChild != instanceIDParent) { unCN <- c(instanceIDChild, unCN, "jointemp") dataFrame[instanceIDChild] <- unColChild - dataFrame["jointemp"] <- unColChild - }else{ + dataFrame[ , "jointemp"] <- unColChild + } else { unCN <- c(unCN, "jointemp") - dataFrame["jointemp"] <- unColChild + dataFrame[ , "jointemp"] <- unColChild } - - parentDf["jointemp"] <- parentDf[,instanceIDParent] - + + parentDf[, "jointemp"] <- parentDf[,instanceIDParent] + dataFrame <- dataFrame[ unCN ] - - dataFrame <- left_join(dataFrame, parentDf, by="jointemp") + + ### Now ready for a left join + dataFrame <- plyr::join(dataFrame, parentDf, by = "jointemp", type = "left") dataFrame["jointemp"] <- NULL - - if(parent=="MainDataFrame_edited"){ + + + if (parent == "MainDataFrame") { + break - }else{ - child <- levelsOfDF[levelsOfDF$name==parent, "name"] - parent <- levelsOfDF[levelsOfDF$name==parent, "parent"] + } else { + child <- levelsOfDF[levelsOfDF$name == parent, "name"] + parent <- levelsOfDF[levelsOfDF$name == parent, "parent"] } } - - write.csv(dataFrame,paste(mainDir,"/data/",dbr,"_edited.csv",sep = ""), row.names = FALSE, na = "") + + cat("\n\n Saving edited version of ", dbr, " ...\n") + write.csv(dataFrame,paste(mainDir,"/data/",dbr,"-edited.csv",sep = ""), row.names = FALSE, na = "") + } - + } + + + ## Compute indicators if defined ################################################## - cat("\n\nCompute indicators if defined..\n") - if(app=="shiny"){ + if (app == "shiny") { progress$set(message = "Computing indicators (if defined) in progress...") updateProgress() } + cat("\n\n Now computing all calculated indicators if defined..\n") result <- kobo_create_indicators(form) - if(class(result) == "try-error"){ + + if (class(result) == "try-error") { return(structure(result, class = "try-error")) } - - - + + + dico <- read.csv(paste0(mainDir,"/data/dico_",form,".csv"), encoding = "UTF-8", na.strings = "") - MainDataFrame_edited <- read.csv(paste(mainDir,"/data/MainDataFrame_edited.csv",sep = ""), encoding = "UTF-8", na.strings = "NA") + + MainDataFrame <- read.csv(paste(mainDir,"/data/MainDataFrame-edited.csv",sep = ""), encoding = "UTF-8", na.strings = "NA") + ## Re-encoding data now based on the dictionnary -- ############################## ## the xlsform dictionnary can be adjusted this script re-runned till satisfaction cat("\n\n\n Now re-encode data \n\n\n\n") cat("\n\nCompute indicators if defined..\n") - if(app=="shiny"){ + if (app == "shiny") { progress$set(message = "Re-encoding data now based on the dictionnary in progress...") updateProgress() } - - MainDataFrame_edited <- kobo_encode(MainDataFrame_edited, dico) + + + MainDataFrame <- kobo_encode(MainDataFrame, dico) + + ## loading nested frame for (dbr in levelsOfDF$name) { - dataFrame <- read.csv(paste(mainDir,"/data/",dbr,"_edited.csv",sep = ""),stringsAsFactors = F) + dataFrame <- read.csv(paste(mainDir,"/data/",dbr,"-edited.csv",sep = ""),stringsAsFactors = F) dataFrame <- kobo_encode(dataFrame, dico) - write.csv(dataFrame,paste(mainDir,"/data/",dbr,"_edited.csv",sep = ""), row.names = FALSE, na = "") + write.csv(dataFrame,paste(mainDir,"/data/",dbr,"-encoded.csv",sep = ""), row.names = FALSE, na = "") + cat("\n\nRe-encode",dbr,"..\n") } - if(app=="shiny"){ + if (app == "shiny") { updateProgress() } - write.csv(MainDataFrame_edited,paste(mainDir,"/data/MainDataFrame_edited.csv",sep = ""), row.names = FALSE, na = "") + + write.csv(MainDataFrame,paste(mainDir,"/data/MainDataFrame-encoded.csv",sep = ""), row.names = FALSE, na = "") + return(TRUE) }, error = function(err) { - print("kobo_load_data_ERROR") + print("There was an error in the data processing step!!! \n\n") return(structure(err, class = "try-error")) }) } diff --git a/R/kobo_prepare_form.R b/R/kobo_prepare_form.R index 22d10f4..e68cd19 100644 --- a/R/kobo_prepare_form.R +++ b/R/kobo_prepare_form.R @@ -45,7 +45,7 @@ kobo_prepare_form <- function(form = "form.xls") { form_tmp <- paste(mainDir, "data", form, sep = "/", collapse = "/") - ### First review all questions from survey sheet ################################################# + # Survey sheet ###################################### survey <- tryCatch({ as.data.frame(read_excel(form_tmp, sheet = "survey"), stringsAsFactors = FALSE) #read survey sheet from the form @@ -85,6 +85,12 @@ kobo_prepare_form <- function(form = "form.xls") { ) }) + + cat("################################# \n") + cat("### Checking now survey sheet ## \n") + cat("################################# \n") + + namesOfSur <- c("type", "name" , "label") ## Rename the variable label @@ -122,11 +128,11 @@ kobo_prepare_form <- function(form = "form.xls") { } cat("Checking now for additional information within your xlsform. Note that you can insert them in the xls and re-run the function! \n \n ") - ### add column if not present ################################################# + ### Add column if not present if ("labelReport" %in% colnames(survey)) { cat(" Good: You have a column `labelReport` in your survey worksheet.\n"); } else { - cat(" No column `labelReport` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...\n"); + cat(" No column `labelReport` in your survey worksheet. Creating a dummy one for the moment based on the initial one - trimmed to 80 characters (see readme file). ...\n"); survey["labelReport"] <- substr(survey[,"label"],1,80) } namesOfSur <- c(namesOfSur,"labelReport") @@ -254,7 +260,7 @@ kobo_prepare_form <- function(form = "form.xls") { survey[is.na(survey)] <- "" - #################################Styling part for survey sheet########################## + #### Styling part for survey sheet sheetname <- "survey" if (!is.null(xlsx::getSheets(wb)[[sheetname]])) xlsx::removeSheet(wb, sheetname) @@ -341,7 +347,7 @@ kobo_prepare_form <- function(form = "form.xls") { cat("\n********************Survey sheet, ready to be used*********************\n \n") - #################################### choices sheet ###################################### + # Choices sheet ###################################### choices <- tryCatch({ as.data.frame(read_excel(form_tmp, sheet = "choices"), stringsAsFactors = FALSE) #read survey sheet from the form @@ -356,9 +362,9 @@ kobo_prepare_form <- function(form = "form.xls") { check.names = F ) }) - - cat("\n \n Checking now choices sheet \n \n") - + cat("################################# \n") + cat("### Checking now choices sheet ## \n") + cat("################################# \n") ## Rename the variable label names(choices)[tolower(names(choices)) == "label::english"] <- "label" @@ -368,21 +374,42 @@ kobo_prepare_form <- function(form = "form.xls") { return(structure('Please make sure the choices sheet have the following columns "type", "name" , "label"', class = "try-error")) } - ### add column if not present ################################################# + ### add column if not present if ("order" %in% colnames(choices)) { - cat("1- Good: You have a column `order` in your choices worksheet.\n"); + cat(" Good: You have a column `order` in your choices worksheet.\n"); } else { - cat("1- No column `order` in your choices worksheet. Creating a dummy one for the moment...\n"); + cat(" No column `order` in your choices worksheet. Creating a dummy one for the moment...\n"); choices$order <- "" } if ("labelReport" %in% colnames(choices)) { - cat("2- Good: You have a column `labelReport` in your choices worksheet.\n"); - } else { - cat("2- No column `labelReport` in your choices worksheet. Creating a dummy one for the moment...\n"); - choices["labelReport"] <- substr(choices[,"label"],1,80) - } - - namesOfCho <- c("list_name", "name", "label", "labelReport", "order") + cat(" Good: You have a column `labelReport` in your choices worksheet.\n"); + } else { + cat(" No column `labelReport` in your choices worksheet. Creating a dummy one for the moment based on the initial one - trimmed to 50 characters...\n"); + choices["labelReport"] <- substr(choices[,"label"],1,50) + } + + if ("weight" %in% colnames(choices)) + { + cat(" Good: You have a column `weight` in your `choices` worksheet.\n"); + } else + {cat(" No column `weight` in your `choices` worksheet. Creating a dummy one for the moment...\n"); + choices$weight <- ""} + + if ("recategorise" %in% colnames(choices)) + { + cat(" Good: You have a column `recategorise` in your `choices` worksheet.\n"); + } else + {cat(" No column `recategorise` in your `choices` worksheet. Creating a dummy one for the moment...\n"); + choices$recategorise <- ""} + + if ("score" %in% colnames(choices)) + { + cat(" Good: You have a column `score` in your `choices` worksheet.\n"); + } else + {cat(" No column `score` in your `choices` worksheet. Creating a dummy one for the moment...\n"); + choices$score <- ""} + + namesOfCho <- c("list_name", "name", "label", "labelReport", "order", "weight","score","recategorise") choices <- choices[ ,namesOfCho] sheetname <- "choices" @@ -408,205 +435,64 @@ kobo_prepare_form <- function(form = "form.xls") { xlsx::setColumnWidth(choicesSheet, 2:3, 30) cat("\n********************Choices sheet, ready to be used*********************\n \n") - #################################### indicator sheet ###################################### - cat("\n \n Checking now indicator sheet \n \n") - indicator <- tryCatch({ - as.data.frame(read_excel(form_tmp, sheet = "indicator"),stringsAsFactors = FALSE) - }, error = function(err) { - data.frame( - type = character(), - fullname = character(), - label = character(), - chapter = character(), - disaggregation = character(), - correlate = character(), - sensitive = character(), - anonymise = character(), - cluster = character(), - predict = character(), - variable = character(), - mappoint = character(), - mappoly = character(), - structuralequation = character(), - frame = character(), - listname = character(), - calculation = character(), - stringsAsFactors = FALSE - ) - }) - if ("type" %in% colnames(indicator)) { - cat("1- Good: You have a column `type` in your indicator worksheet.\n"); - } else { - cat("1- No column `type` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$type <- "" - } - if ("fullname" %in% colnames(indicator)) { - cat("2- Good: You have a column `fullname` in your indicator worksheet.\n"); - } else { - cat("2- No column `fullname` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$fullname <- "" - } - if ("label" %in% colnames(indicator)) { - cat("3- Good: You have a column `label` in your indicator worksheet.\n"); - } else { - cat("3- No column `label` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$label <- "" - } - if ("chapter" %in% colnames(indicator)) { - cat("4- Good: You have a column `chapter` in your indicator worksheet.\n"); - } else { - cat("4- No column `chapter` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$chapter <- "" - } - if ("disaggregation" %in% colnames(indicator)) { - cat("5- Good: You have a column `disaggregation` in your indicator worksheet.\n"); - } else { - cat("5- No column `disaggregation` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$disaggregation <- "" - } - if ("correlate" %in% colnames(indicator)) { - cat("6- Good: You have a column `correlate` in your indicator worksheet.\n"); - } else { - cat("6- No column `correlate` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$correlate <- "" - } + ### Settings sheet ###################################### - if ("sensitive" %in% colnames(indicator)) { - cat("7- Good: You have a column `sensitive` in your indicator worksheet.\n"); - } else { - cat("7- No column `sensitive` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$sensitive <- "" - } - if ("anonymise" %in% colnames(indicator)) { - cat("8- Good: You have a column `anonymise` in your indicator worksheet.\n"); - } else { - cat("8- No column `anonymise` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$anonymise <- "" - } - if ("cluster" %in% colnames(indicator)) { - cat("9- Good: You have a column `cluster` in your indicator worksheet.\n"); - } else { - cat("9- No column `cluster` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$cluster <- "" - } - if ("predict" %in% colnames(indicator)) { - cat("10- Good: You have a column `predict` in your indicator worksheet.\n"); - } else { - cat("10- No column `predict` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$predict <- "" - } - if ("variable" %in% colnames(indicator)) { - cat("11- Good: You have a column `variable` in your indicator worksheet.\n"); - } else { - cat("11- No column `variable` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$variable <- "" - } - if ("mappoint" %in% colnames(indicator)) { - cat("12- Good: You have a column `mappoint` in your indicator worksheet.\n"); - } else { - cat("12- No column `mappoint` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$mappoint <- "" - } - if ("mappoly" %in% colnames(indicator)) { - cat("13- Good: You have a column `mappoly` in your indicator worksheet.\n"); - } else { - cat("13- No column `mappoly` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$mappoly <- "" - } - if ("structuralequation" %in% colnames(indicator)) { - cat("14- Good: You have a column `structuralequation` in your indicator worksheet.\n"); - } else { - cat("14- No column `structuralequation` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$structuralequation <- "" - } - if ("frame" %in% colnames(indicator)) { - cat("15- Good: You have a column `frame` in your indicator worksheet.\n"); - } else { - cat("15- No column `frame` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$frame <- "" - } - if ("listname" %in% colnames(indicator)) { - cat("16- Good: You have a column `listname` in your indicator worksheet.\n"); - } else { - cat("16- No column `listname` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$listname <- "" - } - if ("calculation" %in% colnames(indicator)) { - cat("17- Good: You have a column `calculation` in your indicator worksheet.\n"); - } else { - cat("17- No column `calculation` in your indicator worksheet. Creating a dummy one for the moment...\n"); - indicator$calculation <- "" - } - indicator <- indicator[ ,c("type","fullname","label", "chapter", "disaggregation", "correlate", "sensitive", - "anonymise", "cluster", "predict", "variable", "mappoint", "mappoly", "structuralequation", "frame", "listname","calculation")] + cat("\n\n################################### \n") + cat("### Checking now settings sheet ## \n") + cat("################################### \n\n") - sheetname <- "indicator" - if (!is.null(xlsx::getSheets(wb)[[sheetname]])) - xlsx::removeSheet(wb, sheetname) - indicatorSheet <- xlsx::createSheet(wb, sheetName = sheetname) - xlsx::addDataFrame(indicator, indicatorSheet, col.names = TRUE, row.names = FALSE) - from <- "A1" - to <- dfref[dfref$key == length(indicator),"val"] - xlsx::addAutoFilter(indicatorSheet, paste(from,":",to,sep = "")) - rows <- xlsx::getRows(indicatorSheet) # get rows - cells <- xlsx::getCells(rows) - headerSt <- xlsx::CellStyle(wb) + - xlsx::Font(wb, isBold = TRUE, isItalic = FALSE, color = "white", heightInPoints = 13) + - xlsx::Fill(backgroundColor = "GREY_50_PERCENT",foregroundColor = "GREY_50_PERCENT", - pattern = "SOLID_FOREGROUND") + - xlsx::Border(color = "GREY_80_PERCENT", position = c("TOP", "BOTTOM"), "BORDER_THIN") - highlight <- paste("1",c(1:length(indicator)),sep = ".") - lapply(names(cells[highlight]), - function(ii) xlsx::setCellStyle(cells[[ii]], headerSt)) - xlsx::autoSizeColumn(indicatorSheet, 1:length(survey)) - cat("\n********************Indicator sheet, ready to be used*********************\n \n") - #################################### settings sheet ###################################### - cat("\n \n Checking now settings sheet \n \n") - settings <- tryCatch({ - as.data.frame(read_excel(form_tmp, sheet = "settings"), - stringsAsFactors = FALSE) - }, error = function(err) { - data.frame( - form_title = character(), - form_id = character(), - default_language = character(), - stringsAsFactors = FALSE - ) - }) + settings <- tryCatch({ + as.data.frame(read_excel(form_tmp, sheet = "settings"), + stringsAsFactors = FALSE) + }, error = function(err) { + data.frame( + form_title = character(), + form_id = character(), + default_language = character(), + stringsAsFactors = FALSE + ) + }) + + sheetname <- "settings" + if (!is.null(xlsx::getSheets(wb)[[sheetname]])) + xlsx::removeSheet(wb, sheetname) + settingsSheet <- xlsx::createSheet(wb, sheetName = sheetname) #create sheet with settings name + xlsx::addDataFrame(settings, settingsSheet, col.names = TRUE, row.names = FALSE) #add settings data frame to this sheet + + from <- "A1" + to <- dfref[dfref$key == length(settings),"val"] + + xlsx::addAutoFilter(settingsSheet, paste(from,":",to,sep = "")) + rows <- xlsx::getRows(settingsSheet) # get rows + cells <- xlsx::getCells(rows) + headerSt <- xlsx::CellStyle(wb) + + xlsx::Font(wb, isBold = TRUE, isItalic = FALSE, color = "white", heightInPoints = 13) + + xlsx::Fill(backgroundColor = "GREY_50_PERCENT",foregroundColor = "GREY_50_PERCENT", + pattern = "SOLID_FOREGROUND") + + xlsx::Border(color = "GREY_80_PERCENT", position = c("TOP", "BOTTOM"), "BORDER_THIN") + highlight <- paste("1",c(1:length(settings)),sep = ".") + lapply(names(cells[highlight]), + function(ii) xlsx::setCellStyle(cells[[ii]], headerSt)) + xlsx::autoSizeColumn(settingsSheet, 1:length(survey)) + cat("\n******************** Settings sheet, ready to be used*********************\n \n") + + + + + + + + ### Analysis settings sheet ###################################### + + + cat("\n\n######################################### \n") + cat("### Checking now analysis settings sheet ## \n") + cat("############################################ \n\n") - sheetname <- "settings" - if (!is.null(xlsx::getSheets(wb)[[sheetname]])) - xlsx::removeSheet(wb, sheetname) - settingsSheet <- xlsx::createSheet(wb, sheetName = sheetname) #create sheet with settings name - xlsx::addDataFrame(settings, settingsSheet, col.names = TRUE, row.names = FALSE) #add settings data frame to this sheet - from <- "A1" - to <- dfref[dfref$key == length(settings),"val"] - xlsx::addAutoFilter(settingsSheet, paste(from,":",to,sep = "")) - rows <- xlsx::getRows(settingsSheet) # get rows - cells <- xlsx::getCells(rows) - headerSt <- xlsx::CellStyle(wb) + - xlsx::Font(wb, isBold = TRUE, isItalic = FALSE, color = "white", heightInPoints = 13) + - xlsx::Fill(backgroundColor = "GREY_50_PERCENT",foregroundColor = "GREY_50_PERCENT", - pattern = "SOLID_FOREGROUND") + - xlsx::Border(color = "GREY_80_PERCENT", position = c("TOP", "BOTTOM"), "BORDER_THIN") - highlight <- paste("1",c(1:length(settings)),sep = ".") - lapply(names(cells[highlight]), - function(ii) xlsx::setCellStyle(cells[[ii]], headerSt)) - xlsx::autoSizeColumn(settingsSheet, 1:length(survey)) - cat("\n********************Settings sheet, ready to be used*********************\n \n") - - - - - - - - #################################### analysis settings sheet ###################################### - cat("\n \n Checking now analysis settings sheet \n \n") analysisSettings <- tryCatch({ as.data.frame(read_excel(form_tmp, sheet = "analysisSettings"), stringsAsFactors = FALSE) @@ -620,131 +506,131 @@ kobo_prepare_form <- function(form = "form.xls") { stringsAsFactors = FALSE ) }) - - if(!"sample_type" %in% analysisSettings$name){ + + if (!"sample_type" %in% analysisSettings$name) { analysisSettings <- rbind(analysisSettings, data.frame(name = "sample_type", label = "Sample type of the project", options = "1. No sampling(type 1) 2. Cluster sample (type 2) 3. Stratified sample (type 3)", - value = NA, - path =NA, + value = "No sampling (type 1)", + path = NA, stringsAsFactors = FALSE) ) } - - if(!"variable_name" %in% analysisSettings$name){ + + if (!"variable_name" %in% analysisSettings$name) { analysisSettings <- rbind(analysisSettings, data.frame(name = "variable_name", label = "If there is sampling, select the name of cluster variable that will be used to join the weight file with the main file, please make sure the name of this variable exists in both files", options = NA, value = NA, - path =NA, + path = NA, stringsAsFactors = FALSE) ) } - - if(!"weights_info" %in% analysisSettings$name){ + + if (!"weights_info" %in% analysisSettings$name) { analysisSettings <- rbind(analysisSettings, data.frame(name = "weights_info", label = "If there is sampling, weights file that will be used in Stratified or cluster sample", options = NA, value = NA, - path =NA, + path = NA, stringsAsFactors = FALSE) ) } - - if(!"weightsVariable" %in% analysisSettings$name){ + + if (!"weightsVariable" %in% analysisSettings$name) { analysisSettings <- rbind(analysisSettings, data.frame(name = "weightsVariable", label = "If there is sampling, the variable that contains the weights in weights file", options = NA, value = NA, - path =NA, + path = NA, stringsAsFactors = FALSE) ) } - - if(!"numberOfClusters" %in% analysisSettings$name){ + + if (!"numberOfClusters" %in% analysisSettings$name) { analysisSettings <- rbind(analysisSettings, data.frame(name = "numberOfClusters", label = "If the sample type is cluster sample, enter number of clusters", options = NA, value = NA, - path =NA, + path = NA, stringsAsFactors = FALSE) ) } - - if(!"cleaning_log" %in% analysisSettings$name){ + + if (!"cleaning_log" %in% analysisSettings$name) { analysisSettings <- rbind(analysisSettings, data.frame(name = "cleaning_log", label = "cleaning log plan for the project", options = "1. Yes 2. No, 3. csv filename", - value = NA, - path =NA, + value = "2. No", + path = NA, stringsAsFactors = FALSE) ) } - - if(!"MainDataFrame" %in% analysisSettings$name){ + + if (!"MainDataFrame" %in% analysisSettings$name) { analysisSettings <- rbind(analysisSettings, data.frame(name = "MainDataFrame", label = "Name and the path of MainDataFrame", options = NA, - value = NA, - path =NA, + value = "MainDataFrame", + path = paste0(mainDir,"/data/MainDataFrame.csv"), stringsAsFactors = FALSE) ) } - + levelsOfDF <- kobo_get_dataframes_levels(form) - levelsOfDF <- levelsOfDF[levelsOfDF$name!="MainDataFrame",] - - if(nrow(levelsOfDF)!=0){ + levelsOfDF <- levelsOfDF[levelsOfDF$name != "MainDataFrame",] + + if (nrow(levelsOfDF) != 0) { for (dbr in levelsOfDF$name) { - child <- levelsOfDF[levelsOfDF$name==dbr, "name"] - parent <- levelsOfDF[levelsOfDF$name==dbr, "parent"] - - if(!dbr %in% analysisSettings$name){ + child <- levelsOfDF[levelsOfDF$name == dbr, "name"] + parent <- levelsOfDF[levelsOfDF$name == dbr, "parent"] + + if (!dbr %in% analysisSettings$name) { analysisSettings <- rbind(analysisSettings, data.frame(name = dbr, label = paste("Name and the path of", dbr), options = NA, - value = NA, - path =NA, + value = paste0( dbr,".csv"), + path = paste0(mainDir,"/data/", dbr,".csv"), stringsAsFactors = FALSE) ) } - - if(!paste0("instanceID_", child, "_", parent) %in% analysisSettings$name){ + + if (!paste0("instanceID_", child, "_", parent) %in% analysisSettings$name) { analysisSettings <- rbind(analysisSettings, data.frame(name = paste0("instanceID_", child, "_", parent), label = paste0("The instanceID between the child (", child, ") and the parent (", parent, ")" ), options = NA, - value = NA, - path =NA, + value = "instanceID", + path = NA, stringsAsFactors = FALSE) ) } - - if(!paste0("instanceID_", parent, "_", child) %in% analysisSettings$name){ + + if (!paste0("instanceID_", parent, "_", child) %in% analysisSettings$name) { analysisSettings <- rbind(analysisSettings, data.frame(name = paste0("instanceID_", parent, "_", child), label = paste0("The instanceID between the parent (", parent, ") and the child (", child, ")" ), options = NA, - value = NA, - path =NA, + value = "instanceID", + path = NA, stringsAsFactors = FALSE) ) } - - + + } } - - - + + + sheetname <- "analysisSettings" if (!is.null(xlsx::getSheets(wb)[[sheetname]])) xlsx::removeSheet(wb, sheetname) @@ -764,13 +650,207 @@ kobo_prepare_form <- function(form = "form.xls") { lapply(names(cells[highlight]), function(ii) xlsx::setCellStyle(cells[[ii]], headerSt)) xlsx::autoSizeColumn(settingsSheet, 1:length(survey)) - cat("\n********************analysis Settings sheet, ready to be used*********************\n \n") - - + cat("\n******************** Project Analysis Settings sheet, ready to be used*********************\n \n") + + + + + ## Indicator sheet ###################################### + + + cat("################################### \n") + cat("### Checking now indicator sheet ## \n") + cat("################################### \n") + + + indicator <- tryCatch({ + as.data.frame(read_excel(form_tmp, sheet = "indicator"),stringsAsFactors = FALSE) + }, error = function(err) { + data.frame( + type = character(), + fullname = character(), + labelReport = character(), + hintReport = character(), + frame = character(), + listname = character(), + calculation = character(), + chapter = character(), + variable = character(), + disaggregation = character(), + correlate = character(), + anonymise = character(), + cluster = character(), + predict = character(), + variable = character(), + mappoint = character(), + mappoly = character(), + structuralequation.risk = character(), + structuralequation.coping = character(), + structuralequation.resilience = character(), + stringsAsFactors = FALSE + ) + } + ) + if ("type" %in% colnames(indicator)) { + cat(" Good: You have a column `type` in your indicator worksheet.\n"); + } else { + cat(" No column `type` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$type <- "" + } + if ("fullname" %in% colnames(indicator)) { + cat(" Good: You have a column `fullname` in your indicator worksheet.\n"); + } else { + cat(" No column `fullname` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$fullname <- "" + } + if ("frame" %in% colnames(indicator)) { + cat(" Good: You have a column `frame` in your indicator worksheet.\n"); + } else { + cat(" No column `frame` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$frame <- "" + } + if ("labelReport" %in% colnames(indicator)) { + cat(" Good: You have a column `labelReport` in your indicator worksheet.\n"); + } else { + cat(" No column `labelReport` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$labelReport <- "" + } + if ("hintReport" %in% colnames(indicator)) { + cat(" Good: You have a column `hintReport` in your indicator worksheet.\n"); + } else { + cat(" No column `hintReport` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$hintReport <- "" + } + if ("listname" %in% colnames(indicator)) { + cat(" Good: You have a column `listname` in your indicator worksheet.\n"); + } else { + cat(" No column `listname` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$listname <- "" + } + if ("calculation" %in% colnames(indicator)) { + cat(" Good: You have a column `calculation` in your indicator worksheet.\n"); + } else { + cat(" No column `calculation` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$calculation <- "" + } + if ("chapter" %in% colnames(indicator)) { + cat(" Good: You have a column `chapter` in your indicator worksheet.\n"); + } else { + cat(" No column `chapter` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$chapter <- "" + } + if ("variable" %in% colnames(indicator)) { + cat(" Good: You have a column `variable` in your indicator worksheet.\n"); + } else { + cat(" No column `variable` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$variable <- "" + } + if ("disaggregation" %in% colnames(indicator)) { + cat(" Good: You have a column `disaggregation` in your indicator worksheet.\n"); + } else { + cat(" No column `disaggregation` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$disaggregation <- "" + } + if ("correlate" %in% colnames(indicator)) { + cat(" Good: You have a column `correlate` in your indicator worksheet.\n"); + } else { + cat(" No column `correlate` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$correlate <- "" + } + if ("anonymise" %in% colnames(indicator)) { + cat(" Good: You have a column `anonymise` in your indicator worksheet.\n"); + } else { + cat(" No column `anonymise` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$anonymise <- "" + } + if ("cluster" %in% colnames(indicator)) { + cat(" Good: You have a column `cluster` in your indicator worksheet.\n"); + } else { + cat(" No column `cluster` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$cluster <- "" + } + if ("predict" %in% colnames(indicator)) { + cat(" Good: You have a column `predict` in your indicator worksheet.\n"); + } else { + cat(" No column `predict` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$predict <- "" + } + if ("variable" %in% colnames(indicator)) { + cat(" Good: You have a column `variable` in your indicator worksheet.\n"); + } else { + cat(" No column `variable` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$variable <- "" + } + if ("mappoint" %in% colnames(indicator)) { + cat(" Good: You have a column `mappoint` in your indicator worksheet.\n"); + } else { + cat(" No column `mappoint` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$mappoint <- "" + } + if ("mappoly" %in% colnames(indicator)) { + cat(" Good: You have a column `mappoly` in your indicator worksheet.\n"); + } else { + cat(" No column `mappoly` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$mappoly <- "" + } + if ("structuralequation.risk" %in% colnames(indicator)) { + cat(" Good: You have a column `structuralequation.risk` in your indicator worksheet. This will be used to configure the vulnerability structural equation model\n"); + } else { + cat(" No column `structuralequation.risk` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$structuralequation.risk <- "" + } + if ("structuralequation.coping" %in% colnames(indicator)) { + cat(" Good: You have a column `structuralequation.coping` in your indicator worksheet. This will be used to configure the vulnerability structural equation model\n"); + } else { + cat(" No column `structuralequation.coping` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$structuralequation.coping <- "" + } + if ("structuralequation.resilience" %in% colnames(indicator)) { + cat(" Good: You have a column `structuralequation.resilience` in your indicator worksheet. This will be used to configure the vulnerability structural equation model\n"); + } else { + cat(" No column `structuralequation.resilience` in your indicator worksheet. Creating a dummy one for the moment...\n"); + indicator$structuralequation.resilience <- "" + } + + indicator <- indicator[ ,c("type","fullname","labelReport", "hintReport", + "frame", "listname","calculation", + "chapter", "variable", "disaggregation", "correlate", + "anonymise", "cluster", "predict", "variable", "mappoint", "mappoly", + "structuralequation.risk","structuralequation.coping","structuralequation.resilience")] + + sheetname <- "indicator" + if (!is.null(xlsx::getSheets(wb)[[sheetname]])) + xlsx::removeSheet(wb, sheetname) + indicatorSheet <- xlsx::createSheet(wb, sheetName = sheetname) + xlsx::addDataFrame(indicator, indicatorSheet, col.names = TRUE, row.names = FALSE) + from <- "A1" + to <- dfref[dfref$key == length(indicator),"val"] + xlsx::addAutoFilter(indicatorSheet, paste(from,":",to,sep = "")) + + # get rows + rows <- xlsx::getRows(indicatorSheet) + cells <- xlsx::getCells(rows) + headerSt <- xlsx::CellStyle(wb) + + xlsx::Font(wb, isBold = TRUE, isItalic = FALSE, color = "white", heightInPoints = 13) + + xlsx::Fill(backgroundColor = "GREY_50_PERCENT",foregroundColor = "GREY_50_PERCENT", + pattern = "SOLID_FOREGROUND") + + xlsx::Border(color = "GREY_80_PERCENT", position = c("TOP", "BOTTOM"), "BORDER_THIN") + highlight <- paste("1",c(1:length(indicator)),sep = ".") + lapply(names(cells[highlight]), + function(ii) xlsx::setCellStyle(cells[[ii]], headerSt)) + xlsx::autoSizeColumn(indicatorSheet, 1:length(survey)) + cat("\n******************** Indicator sheet, ready to be used *********************\n \n") + + if (file.exists(form_tmp)) file.remove(form_tmp) xlsx::saveWorkbook(wb, form_tmp) + + + cat("\n******************** The XLSFORM has now been extended to include your analysis plan *********************\n \n") + + }, error = function(err) { - print("kobo_prepare_form_ERROR") + print("There was an error in the xlsform preparation step!!! \n\n") return(structure(err, class = "try-error")) }) diff --git a/R/kobo_unhcr_style_bar.R b/R/kobo_unhcr_style_bar.R new file mode 100644 index 0000000..9e5ae93 --- /dev/null +++ b/R/kobo_unhcr_style_bar.R @@ -0,0 +1,55 @@ +#' @name kobo_unhcr_style_bar +#' @rdname kobo_unhcr_style_bar +#' @title UNHCR ggplot2 theme +#' +#' @description Return ggplot2 styling for bar chart +#' +#' @return Return UNHCR Style +#' +#' @author Edouard Legoupil - with inspiration from bbc +#' +#' @examples +#' kobo_unhcr_style_bar() +#' +#' @export kobo_unhcr_style_bar +#' + +kobo_unhcr_style_bar <- function() { + font <- "Lato" + ggplot2::theme( + + #This sets the font, size, type and colour of text for the chart's title + plot.title = ggplot2::element_text(family = font, size = 12, face = "bold", color = "#222222"), + + #This sets the font, size, type and colour of text for the chart's subtitle, as well as setting a margin between the title and the subtitle + plot.subtitle = ggplot2::element_text(family = font, size = 11, margin = ggplot2::margin(9,0,9,0)), + plot.caption = ggplot2::element_blank(), + + #This sets the position and alignment of the legend, removes a title and backround for it and sets the requirements for any text within the legend. The legend may often need some more manual tweaking when it comes to its exact position based on the plot coordinates. + legend.position = "top", + legend.text.align = 0, + legend.background = ggplot2::element_blank(), + legend.title = ggplot2::element_blank(), + legend.key = ggplot2::element_blank(), + legend.text = ggplot2::element_text(family = font, size = 9, color = "#222222"), + + #This sets the text font, size and colour for the axis test, as well as setting the margins and removes lines and ticks. In some cases, axis lines and axis ticks are things we would want to have in the chart + axis.title = ggplot2::element_blank(), + axis.text = ggplot2::element_text(family = font, size = 11, color = "#222222"), + axis.text.x = ggplot2::element_text(margin = ggplot2::margin(5, b = 9)), + axis.ticks = ggplot2::element_blank(), + axis.line = ggplot2::element_blank(), + + #This removes all minor gridlines and adds major y gridlines. In many cases you will want to change this to remove y gridlines and add x gridlines. + panel.grid.minor = ggplot2::element_blank(), + panel.grid.major.x = ggplot2::element_line(color = "#cbcbcb"), + panel.grid.major.y = ggplot2::element_blank(), + + #This sets the panel background as blank, removing the standard grey ggplot background colour from the plot + panel.background = ggplot2::element_blank(), + + #This sets the panel background for facet-wrapped plots to white, removing the standard grey ggplot background colour and sets the title size of the facet-wrap title to font size 22 + strip.background = ggplot2::element_rect(fill = "white"), + strip.text = ggplot2::element_text(size = 11, hjust = 0) + ) + } diff --git a/R/kobo_unhcr_style_histo.R b/R/kobo_unhcr_style_histo.R new file mode 100644 index 0000000..bd4917d --- /dev/null +++ b/R/kobo_unhcr_style_histo.R @@ -0,0 +1,55 @@ +#' @name kobo_unhcr_style_histo +#' @rdname kobo_unhcr_style_histo +#' @title UNHCR ggplot2 theme +#' +#' @description Return ggplot2 styling for histogram +#' +#' @return Return UNHCR Style +#' +#' @author Edouard Legoupil - with inspiration from bbc +#' +#' @examples +#' kobo_unhcr_style_histo() +#' +#' @export kobo_unhcr_style_histo +#' + +kobo_unhcr_style_histo <- function() { + font <- "Lato" + ggplot2::theme( + + #This sets the font, size, type and colour of text for the chart's title + plot.title = ggplot2::element_text(family = font, size = 12, face = "bold", color = "#222222"), + + #This sets the font, size, type and colour of text for the chart's subtitle, as well as setting a margin between the title and the subtitle + plot.subtitle = ggplot2::element_text(family = font, size = 11, margin = ggplot2::margin(9,0,9,0)), + plot.caption = ggplot2::element_blank(), + + #This sets the position and alignment of the legend, removes a title and backround for it and sets the requirements for any text within the legend. The legend may often need some more manual tweaking when it comes to its exact position based on the plot coordinates. + legend.position = "top", + legend.text.align = 0, + legend.background = ggplot2::element_blank(), + legend.title = ggplot2::element_blank(), + legend.key = ggplot2::element_blank(), + legend.text = ggplot2::element_text(family = font, size = 9, color = "#222222"), + + #This sets the text font, size and colour for the axis test, as well as setting the margins and removes lines and ticks. In some cases, axis lines and axis ticks are things we would want to have in the chart + axis.title = ggplot2::element_blank(), + axis.text = ggplot2::element_text(family = font, size = 11, color = "#222222"), + axis.text.x = ggplot2::element_text(margin = ggplot2::margin(5, b = 9)), + axis.ticks = ggplot2::element_blank(), + axis.line = ggplot2::element_blank(), + + #This removes all minor gridlines and adds major y gridlines. In many cases you will want to change this to remove y gridlines and add x gridlines. + panel.grid.minor = ggplot2::element_blank(), + panel.grid.major.y = ggplot2::element_line(color = "#cbcbcb"), + panel.grid.major.x = ggplot2::element_blank(), + + #This sets the panel background as blank, removing the standard grey ggplot background colour from the plot + panel.background = ggplot2::element_blank(), + + #This sets the panel background for facet-wrapped plots to white, removing the standard grey ggplot background colour and sets the title size of the facet-wrap title to font size 22 + strip.background = ggplot2::element_rect(fill = "white"), + strip.text = ggplot2::element_text(size = 11, hjust = 0) + ) + } diff --git a/R/kobo_unhcr_style_map.R b/R/kobo_unhcr_style_map.R new file mode 100644 index 0000000..db994a6 --- /dev/null +++ b/R/kobo_unhcr_style_map.R @@ -0,0 +1,62 @@ +#' @name kobo_unhcr_style_map +#' @rdname kobo_unhcr_style_map +#' @title UNHCR ggplot2 theme +#' +#' @description Return ggplot2 styling for maps +#' +#' @return Return UNHCR Style +#' +#' @author Edouard Legoupil - +#' +#' @examples +#' kobo_unhcr_style_map() +#' +#' @export kobo_unhcr_style_map +#' + +kobo_unhcr_style_map <- function() { + font <- "Lato" + ggplot2::theme_minimal() + + ggplot2::theme( + #------------ + ## Plot + # plot.background = element_rect(fill = "transparent",colour = NA), + # plot.background = element_rect(fill = "#f5f5f2", color = NA), + plot.title = element_text(face = "bold", size = 12, hjust = 0, color = "#4e4d47"), + plot.subtitle = element_text(size = 8, hjust = 0, color = "#4e4d47", margin = margin(b = -0.1, t = -0.1, l = 2, unit = "cm"), debug = F), + plot.margin = unit(c(.5,.5,.2,.5), "cm"), + plot.caption = element_text(size = 6, hjust = 0.92, margin = margin(t = 0.2, b = 0, unit = "cm"), color = "#939184"), + + #------------ + ## Panel + panel.border = element_blank(), + # panel.grid.minor = element_line(color = "#ebebe5", size = 0.2), + panel.grid.major = element_line(color = "#ebebe5", size = 0.2), + panel.grid.minor = element_blank(), + # panel.background = element_rect(fill = "#f5f5f2", color = NA), + panel.spacing = unit(c(-.1,0.7,.2,1.7), "cm"), + + #------------ + ## legend + legend.title = element_text(size = 8), + legend.text = element_text(size = 7, hjust = 0, color = "#4e4d47"), + legend.position = "bottom", + legend.box = "horizontal", + # legend.position = c(0.8, 0.03), + legend.text.align = 0, + #legend.background = element_rect(fill = "transparent",colour = NA), + # legend.background = element_rect(fill = "#f5f5f2", color = NA), + legend.background = element_rect(fill = alpha('white', 0.0), color = NA), + + #------------ + ## Axis + axis.line = element_blank(), + axis.text.x = element_blank(), + axis.text.y = element_blank(), + axis.ticks = element_blank(), + axis.title.x = element_blank(), + axis.title.y = element_blank() + + + ) + } diff --git a/R/kobo_unhcr_style_scatter.R b/R/kobo_unhcr_style_scatter.R new file mode 100644 index 0000000..99a539b --- /dev/null +++ b/R/kobo_unhcr_style_scatter.R @@ -0,0 +1,55 @@ +#' @name kobo_unhcr_style_scatter +#' @rdname kobo_unhcr_style_scatter +#' @title UNHCR ggplot2 theme +#' +#' @description Return ggplot2 styling for scatter plot +#' +#' @return Return UNHCR Style +#' +#' @author Edouard Legoupil - with inspiration from bbc +#' +#' @examples +#' kobo_unhcr_style_scatter() +#' +#' @export kobo_unhcr_style_scatter +#' + +kobo_unhcr_style_scatter <- function() { + font <- "Lato" + ggplot2::theme( + + #This sets the font, size, type and colour of text for the chart's title + plot.title = ggplot2::element_text(family = font, size = 12, face = "bold", color = "#222222"), + + #This sets the font, size, type and colour of text for the chart's subtitle, as well as setting a margin between the title and the subtitle + plot.subtitle = ggplot2::element_text(family = font, size = 11, margin = ggplot2::margin(9,0,9,0)), + plot.caption = ggplot2::element_blank(), + + #This sets the position and alignment of the legend, removes a title and backround for it and sets the requirements for any text within the legend. The legend may often need some more manual tweaking when it comes to its exact position based on the plot coordinates. + legend.position = "top", + legend.text.align = 0, + legend.background = ggplot2::element_blank(), + legend.title = ggplot2::element_blank(), + legend.key = ggplot2::element_blank(), + legend.text = ggplot2::element_text(family = font, size = 9, color = "#222222"), + + #This sets the text font, size and colour for the axis test, as well as setting the margins and removes lines and ticks. In some cases, axis lines and axis ticks are things we would want to have in the chart + axis.title = ggplot2::element_blank(), + axis.text = ggplot2::element_text(family = font, size = 11, color = "#222222"), + axis.text.x = ggplot2::element_text(margin = ggplot2::margin(5, b = 9)), + axis.ticks = ggplot2::element_blank(), + axis.line = ggplot2::element_blank(), + + #This removes all minor gridlines and adds major y gridlines. In many cases you will want to change this to remove y gridlines and add x gridlines. + panel.grid.minor = ggplot2::element_blank(), + panel.grid.major.x = ggplot2::element_line(color = "#cbcbcb"), + panel.grid.major.y = ggplot2::element_line(color = "#cbcbcb"), + + #This sets the panel background as blank, removing the standard grey ggplot background colour from the plot + panel.background = ggplot2::element_blank(), + + #This sets the panel background for facet-wrapped plots to white, removing the standard grey ggplot background colour and sets the title size of the facet-wrap title to font size 22 + strip.background = ggplot2::element_rect(fill = "white"), + strip.text = ggplot2::element_text(size = 11, hjust = 0) + ) + } diff --git a/README.md b/README.md index 8591317..1271fe3 100644 --- a/README.md +++ b/README.md @@ -54,21 +54,30 @@ The `koboloadeR` package allows to: To be able to use koboloadeR you will need: - * Java JRE (https://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html): JAVA is required to manipulate excel files. + +## Software installation - * R (https://cran.rstudio.com/). For Windows, choose "install R for the first time". + 1. Install either [Java JRE](https://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html): JAVA is required to manipulate excel files. - * **Only for windows user** RTools (https://cran.r-project.org/bin/windows/Rtools/) - This executable is needed to install the package from github. +If you install, the `JDK` (Java Development kit), Please make sure that `JAVA_HOME` is actually recorded as an [Environment Variable](https://java.com/en/download/help/path.xml). - * R Studio (https://www.rstudio.com/products/rstudio/download/#download) +If you install, the `JRE` (Java Runtime Environment), Please make sure that `JRE_HOME` is actually recorded as an [Environment Variable](https://confluence.atlassian.com/doc/setting-the-java_home-variable-in-windows-8895.html). - -## Software installation - * Install Java JRE: please make sure that JAVA_HOME is actually recorded as an [Environment Variable](https://java.com/en/download/help/path.xml). Note in some case, you may need to reboot your computer to ensure that this environement variable is properly accounted for. - * Install R: follow instruction from the installer. - * Install RTools: follow instruction from the installer. - * Install R Studio: follow instruction from the installer - * Launch R Studio +Once in R, you may double-check that Environement variable are correctly, i.e. JAVA_HOME or JRE_HOME, set by + +> Sys.getenv() + +If JAVA is not correctly set, you will see an installatin error at a latter stage when loading the package `RJava`. + +Note in some case, you may need to reboot your computer to ensure that this environement variable is properly accounted for. + + 2. [Install R](https://cran.rstudio.com/): follow instruction from the installer. + + 3. **Only for windows user** [Install RTools](https://cran.r-project.org/bin/windows/Rtools/): This executable is needed to install the package from github. Follow instruction from the installer. + + 4. [Install R Studio](https://www.rstudio.com/products/rstudio/download/#download) : follow instruction from the installer + +You can now Launch __R Studio__ ### Package installation: koboloadeR from Github (up to date version): @@ -77,7 +86,7 @@ Note that the package is still in beta-version. We hope to have soon a release a * Open R studio interface and within the R console, install `devtools` package: ``` -devtools::install.packages("devtools") +install.packages("devtools") ``` * Install koboloadeR: diff --git a/buildsite.R b/buildsite.R index c5f99df..573b0b6 100644 --- a/buildsite.R +++ b/buildsite.R @@ -6,3 +6,4 @@ library("pkgdown") pkgdown::build_site() +build_vignettes() diff --git a/docs/articles/index.html b/docs/articles/index.html index c5871f7..58e1dbd 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -85,6 +85,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -120,6 +123,7 @@

    All vignettes

    diff --git a/docs/authors.html b/docs/authors.html index 846f94d..8314a55 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -85,6 +85,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/index.html b/docs/index.html index 5891a5c..0a75809 100644 --- a/docs/index.html +++ b/docs/index.html @@ -55,6 +55,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -122,23 +125,27 @@

    Prerequisite

    To be able to use koboloadeR you will need:

    -

    Software installation

    - +
      +
    1. Install either Java JRE: JAVA is required to manipulate excel files.
    2. +
    +

    If you install, the JDK (Java Development kit), Please make sure that JAVA_HOME is actually recorded as an Environment Variable.

    +

    If you install, the JRE (Java Runtime Environment), Please make sure that JRE_HOME is actually recorded as an Environment Variable.

    +

    Once in R, you may double-check that Environement variable are correctly, i.e. JAVA_HOME or JRE_HOME, set by

    +
    +

    Sys.getenv()

    +
    +

    If JAVA is not correctly set, you will see an installatin error at a latter stage when loading the package RJava.

    +

    Note in some case, you may need to reboot your computer to ensure that this environement variable is properly accounted for.

    +
      +
    1. Install R: follow instruction from the installer.

    2. +
    3. Only for windows user Install RTools: This executable is needed to install the package from github. Follow instruction from the installer.

    4. +
    5. Install R Studio : follow instruction from the installer

    6. +
    +

    You can now Launch R Studio

    Package installation: koboloadeR from Github (up to date version):

    @@ -146,7 +153,7 @@

    • Open R studio interface and within the R console, install devtools package:
    -
    devtools::install.packages("devtools")
    +
    install.packages("devtools")
    • Install koboloadeR:
    diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 68610fb..728ade6 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -3,4 +3,5 @@ pkgdown: 1.3.0 pkgdown_sha: ~ articles: tutorial: tutorial.html + tutorial2: tutorial2.html diff --git a/docs/reference/code/run-analysis.R b/docs/reference/code/run-analysis.R index 7312fcd..67a231e 100644 --- a/docs/reference/code/run-analysis.R +++ b/docs/reference/code/run-analysis.R @@ -1,45 +1,25 @@ -#' @title Step by Step run Analysis -#' -#' @author Maher Daoud, Edouard legoupil -#' -#' -#' +######################## +### Console Script ##### +######################## library(koboloadeR) #### Phase 1: Project Configurationn ############# -################## Step1: Analysis project initiation ############# -result <- kobo_projectinit() ## Create analysis project structure -if (class(result) == "try-error") { - print(result) - return(FALSE) -} - -mainDir <- kobo_getMainDirectory() ## return current working directory - -################# Step2: Check if the file is exist ############# -form <- "form.xls" ## The name of the xlsform that exist under data folder -if (!file.exists(paste0(mainDir, "/data/",form))) { - print("Please make sure that this file exists with the same name under the data folder") - return(FALSE) -} - -################## Step3: Extend xlsform with necessary column ############# -result <- kobo_prepare_form(form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} +## Configure name of the xlsform that exist under data folder +# - Change if required but better to keep the defautl one +form <- "form.xls" +## Extend xlsform with necessary column kobo_prepare_form(form) -#### Eventually Generate dummy data -## kobo_dico(form) -## kobo_dummy(form) +### Eventually Generate dummy data (uncomment below if required) + # kobo_dummy(form) -### At this stage you can start working on your xlsform and fill it accordingly!!! +###################################################################################### +### At this stage you can start working on your xlsform and fill it accordingly!!! ### +###################################################################################### -################## Step4: Rename xlsform and Dataframes ################## +## Rename xlsform and Dataframes ## Please make sure in the settings sheet that you mentioned the main data frame and all sub dataframes ## The name field must be filled with the same name of begin-repeat name. ## The name of the Main Data Frame must be always "MainDataFrame", just to indicate that is the main one @@ -47,61 +27,34 @@ kobo_prepare_form(form) # name | label | value | path # 1 MainDataFrame | NA | mainDataFrame.csv | current-working-directory/data/mainDataFrame.csv # 2 br1 | NA | begin-repeat1.csv | current-working-directory/data/begin-repeat1.csv - -result <- kobo_rename_xlsform_dataframes(form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} kobo_rename_xlsform_dataframes(form) - - #### Phase 2: Analysis Plan ############################### - -result <- kobo_check_analysis_plan(form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} kobo_check_analysis_plan(form) - #### Phase 3: Load & process Data ############################### -result <- kobo_load_data(form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} kobo_load_data(form) -#### Phase 4: Generate Reports ############################### -################## Step1: Generate Crunching Report ############# -result <- kobo_crunching_report(form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} +#### Phase 4: Generate Analysis Reports ############################### + +## Generate Crunching Report --> Describe kobo_crunching_report(form) -################## Step2: Generate Cluster Report ############# +## Generate Cluster Report --> Discover household <- read.csv(paste(mainDir, "data", "/MainDataFrame.csv", sep = "/", collapse = "/"), stringsAsFactors = F) ## This dataset will be generated by kobo_load_data -result <- kobo_cluster_report(frame = household, form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} kobo_cluster_report(frame = household, form) -################## Step3: Generate Anonymisation Report ############# +## Generate Prediction Report --> Predict + +## Generate Scoring Report --> Prescribe + + +#### Phase 5: Statistical Disclosure control & Indicator sharing ############################### +## Generate Anonymisation Report household <- read.csv(paste(mainDir, "data", "/MainDataFrame.csv", sep = "/", collapse = "/"), stringsAsFactors = F) ## This dataset will be generated by kobo_load_data -result <- kobo_anonymisation_report(frame = household, form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} kobo_anonymisation_report(frame = household, form) + diff --git a/docs/reference/code/shiny_app/app_main_koboloadeR.R b/docs/reference/code/shiny_app/app_main_koboloadeR.R index 3b368a1..b1b482b 100644 --- a/docs/reference/code/shiny_app/app_main_koboloadeR.R +++ b/docs/reference/code/shiny_app/app_main_koboloadeR.R @@ -497,6 +497,7 @@ server <- shinyServer(function(input, output, session) { updateProgress() settingsDF <- data.frame(name = character(), label = character(), + options = character(), value = character(), path = character(), stringsAsFactors = FALSE @@ -508,7 +509,8 @@ server <- shinyServer(function(input, output, session) { dataFile <- read.csv(inFile$datapath, header=TRUE, sep=input[[paste("separator",projectConfigurationInfo$data[["beginRepeatList"]][i],sep = "")]], stringsAsFactors = FALSE) fileName <- paste("/",projectConfigurationInfo$data[["beginRepeatList"]][i], ".csv", sep="") settingsDF <- rbind(settingsDF, data.frame(name = projectConfigurationInfo$data[["beginRepeatList"]][i], - label = NA, + label = paste("Name and the path of", projectConfigurationInfo$data[["beginRepeatList"]][i]), + options = "", value = paste(projectConfigurationInfo$data[["beginRepeatList"]][i], ".csv", sep=""), path = paste0(mainDir(), "/data", fileName), stringsAsFactors = FALSE @@ -527,7 +529,21 @@ server <- shinyServer(function(input, output, session) { configInfo <- configInfo[!configInfo$name %in% settingsDF$name, ] settingsDF <- rbind(configInfo, settingsDF) settingsDF <- settingsDF[!is.na(settingsDF$name),] - kobo_edit_form(settings = settingsDF ) + + result <- kobo_edit_form(analysisSettings = settingsDF ) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } + updateProgress() projectConfigurationInfo$log[["subAndMainfiles"]] <- TRUE @@ -712,6 +728,7 @@ server <- shinyServer(function(input, output, session) { c( paste0("instanceID_", child, "_", parent), paste0("The instanceID between the child (",child,")", " and the parent (",parent,")"), + options = "", input[[paste("instanceIDInput", child, "child", parent, "parent", sep = "")]], path = "" ) @@ -721,6 +738,7 @@ server <- shinyServer(function(input, output, session) { c( paste0("instanceID_", parent, "_", child), paste0("The instanceID between the parent (",parent,")", " and the child (",child,")"), + options = "", input[[paste("instanceIDInput", parent, "parent", child, "child", sep = "")]], path = "" ) @@ -773,7 +791,22 @@ server <- shinyServer(function(input, output, session) { } updateProgress() - kobo_edit_form(survey = survey, settings = configInfo) + + result <- kobo_edit_form(survey = survey, analysisSettings = configInfo) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } + + removeModal() }, error = function(err) { print("jkfhg8fsdjksdjioerf") @@ -1223,6 +1256,7 @@ server <- shinyServer(function(input, output, session) { tryCatch({ settingsDF <- data.frame(name = character(), label = character(), + options = character(), value = character(), path = character(), stringsAsFactors = FALSE @@ -1257,11 +1291,13 @@ server <- shinyServer(function(input, output, session) { if(sum(input$samplingSelectInput == "No sampling(type 1)")){ settingsDF[lastRow,"name"] <- "sample_type" settingsDF[lastRow,"label"] <- "Sample type of the project" + settingsDF[lastRow,"options"] <- "1. No sampling(type 1) 2. Cluster sample (type 2) 3. Stratified sample (type 3)" settingsDF[lastRow,"value"] <- "No sampling(type 1)" } else if(sum(input$samplingSelectInput == "Cluster sample (type 2)")){ settingsDF[lastRow,"name"] <- "sample_type" settingsDF[lastRow,"label"] <- "Sample type of the project" + settingsDF[lastRow,"options"] <- "1. No sampling(type 1) 2. Cluster sample (type 2) 3. Stratified sample (type 3)" settingsDF[lastRow,"value"] <- input$samplingSelectInput if(sum(input$variableNameCluster == "")){ @@ -1279,7 +1315,8 @@ server <- shinyServer(function(input, output, session) { updateProgress() lastRow <- lastRow+1 settingsDF[lastRow,"name"] <- "variable_name" - settingsDF[lastRow,"label"] <- "The name of cluster variable" + settingsDF[lastRow,"label"] <- "The name of cluster variable that will be used to join the weight file with the main file, please make sure the name of this variable exists in both files" + settingsDF[lastRow,"value"] <- input$variableNameCluster @@ -1310,6 +1347,7 @@ server <- shinyServer(function(input, output, session) { else if(sum(input$samplingSelectInput == "Stratified sample (type 3)")){ settingsDF[lastRow,"name"] <- "sample_type" settingsDF[lastRow,"label"] <- "Sample type of the project" + settingsDF[lastRow,"options"] <- "1. No sampling(type 1) 2. Cluster sample (type 2) 3. Stratified sample (type 3)" settingsDF[lastRow,"value"] <- input$samplingSelectInput updateProgress() if(sum(input$variableNameStratified == "")){ @@ -1349,7 +1387,7 @@ server <- shinyServer(function(input, output, session) { write.csv(dataFile, paste(mainDir(), "data", "/weightsStratified.csv", sep = "/", collapse = "/"), row.names = FALSE) lastRow <- lastRow+1 settingsDF[lastRow,"name"] <- "weights_info" - settingsDF[lastRow,"label"] <- "Weights that will be used in Stratified sample" + settingsDF[lastRow,"label"] <- "Weights file that will be used in Stratified sample" settingsDF[lastRow,"value"] <- "weightsStratified.csv" settingsDF[lastRow,"path"] <- paste(mainDir(), "data", "weightsStratified.csv", sep = "/", collapse = "/") } @@ -1373,6 +1411,7 @@ server <- shinyServer(function(input, output, session) { lastRow <- lastRow+1 settingsDF[lastRow,"name"] <- "cleaning_log" settingsDF[lastRow,"label"] <- "cleaning log plan for the project" + settingsDF[lastRow,"options"] <- "1. Yes 2. No, 3. csv filename" settingsDF[lastRow,"value"] <- "No" }else{ inFilecleaningLog <- input$cleaningLogFileInput @@ -1393,6 +1432,7 @@ server <- shinyServer(function(input, output, session) { lastRow <- lastRow+1 settingsDF[lastRow,"name"] <- "cleaning_log" settingsDF[lastRow,"label"] <- "cleaning log plan for the project" + settingsDF[lastRow,"options"] <- "1. Yes 2. No, 3. csv filename" settingsDF[lastRow,"value"] <- "cleaningLog.csv" settingsDF[lastRow,"path"] <- paste(mainDir(), "data", "/cleaningLog.csv", sep = "/", collapse = "/") } @@ -1405,7 +1445,21 @@ server <- shinyServer(function(input, output, session) { settingsDF <- settingsDF[!is.na(settingsDF$name),] - kobo_edit_form(settings = settingsDF ) + result <- kobo_edit_form(analysisSettings = settingsDF ) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } + + projectConfigurationInfo$log[["isRecordSettingsSaved"]] <- TRUE updateProgress() if(sum(input$samplingSelectInput != "No sampling(type 1)")){ @@ -1544,10 +1598,10 @@ server <- shinyServer(function(input, output, session) { return(FALSE) } if(length(configInfo[configInfo$name=="weightsVariable","value"]) == 0){ - configInfo <- rbind(configInfo, c("weightsVariable", "The variable that contains the weights",input$weightsClusterVariableInput,NA )) + configInfo <- rbind(configInfo, c("weightsVariable", "The variable that contains the weights",NA,input$weightsClusterVariableInput,NA )) }else{ if(is.na(configInfo[configInfo$name=="weightsVariable","value"])){ - configInfo <- rbind(configInfo, c("weightsVariable", "The variable that contains the weights",input$weightsClusterVariableInput,NA )) + configInfo <- rbind(configInfo, c("weightsVariable", "The variable that contains the weights",NA,input$weightsClusterVariableInput,NA )) }else{ configInfo[configInfo$name=="weightsVariable","value"] <- input$weightsClusterVariableInput } @@ -1555,10 +1609,10 @@ server <- shinyServer(function(input, output, session) { } updateProgress() if(length(configInfo[configInfo$name=="numberOfClusters","value"]) == 0){ - configInfo <- rbind(configInfo, c("numberOfClusters", "Number of clusters",input$numberOfClustersInput,NA )) + configInfo <- rbind(configInfo, c("numberOfClusters", "Number of clusters",NA,input$numberOfClustersInput,NA )) }else{ if(is.na(configInfo[configInfo$name=="numberOfClusters","value"])){ - configInfo <- rbind(configInfo, c("numberOfClusters", "Number of clusters",input$numberOfClustersInput,NA )) + configInfo <- rbind(configInfo, c("numberOfClusters", "Number of clusters",NA,input$numberOfClustersInput,NA )) }else{ configInfo[configInfo$name=="numberOfClusters","value"] <- input$numberOfClustersInput } @@ -1583,10 +1637,10 @@ server <- shinyServer(function(input, output, session) { return(FALSE) } if(length(configInfo[configInfo$name=="weightsVariable","value"]) == 0){ - configInfo <- rbind(configInfo, c("weightsVariable", "The variable that contains the weights",input$weightsStratifiedVariableInput,NA )) + configInfo <- rbind(configInfo, c("weightsVariable", "The variable that contains the weights",NA,input$weightsStratifiedVariableInput,NA )) }else{ if(is.na(configInfo[configInfo$name=="weightsVariable","value"])){ - configInfo <- rbind(configInfo, c("weightsVariable", "The variable that contains the weights",input$weightsStratifiedVariableInput,NA )) + configInfo <- rbind(configInfo, c("weightsVariable", "The variable that contains the weights",NA,input$weightsStratifiedVariableInput,NA )) }else{ configInfo[configInfo$name=="weightsVariable","value"] <- input$weightsStratifiedVariableInput } @@ -1595,7 +1649,22 @@ server <- shinyServer(function(input, output, session) { updateProgress() } updateProgress() - kobo_edit_form(settings = configInfo) + + result <- kobo_edit_form(analysisSettings = configInfo) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } + + removeModal() shinyalert("Done, Record Settings Configuration has been successfully saved", "You can find the Settings in 'settings' sheet in xlsform file", @@ -2480,8 +2549,20 @@ server <- shinyServer(function(input, output, session) { #indicator[!is.na(indicator$fullname) & indicator$fullname==indicators[j],] <- NA indicator <-indicator[!is.na(indicator$fullname) & indicator$fullname!=indicators[j],] updateProgress() - kobo_edit_form(indicator = indicator) + result <- kobo_edit_form(indicator = indicator) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } indicatorsIF <- indicatorsInfo[["data"]] indicatorsIF <- indicatorsIF[indicatorsIF$fullname != indicators[j],] @@ -3534,7 +3615,21 @@ server <- shinyServer(function(input, output, session) { updateProgress() indicator <- rbind(indicator, newRow) - kobo_edit_form(indicator = indicator) + + result <- kobo_edit_form(indicator = indicator) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } + updateProgress() indicator <- indicator %>% arrange(fullname) @@ -3710,7 +3805,22 @@ server <- shinyServer(function(input, output, session) { indicatorsIF[!is.na(indicatorsIF$fullname) & indicatorsIF$fullname == selInd, "variable"] = input$subIndicatorVariableInput indicatorsIF[!is.na(indicatorsIF$fullname) & indicatorsIF$fullname == selInd, "listname"] = input$subIndicatorListnameInput updateProgress() - kobo_edit_form(indicator = indicatorsIF) + + + result <- kobo_edit_form(indicator = indicatorsIF) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } + updateProgress() indicatorsIF <- indicatorsIF %>% arrange(fullname) indicatorsInfo[["data"]] <- indicatorsIF @@ -5382,7 +5492,22 @@ server <- shinyServer(function(input, output, session) { survey[!is.na(survey$chapter) & survey$chapter==cahpters[j],"chapter"] <- NA indicator[!is.na(indicator$chapter) & indicator$chapter==cahpters[j],"chapter"] <- NA updateProgress() - kobo_edit_form(survey = survey, indicator = indicator) + + + result <- kobo_edit_form(survey = survey, indicator = indicator) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } + chaptersDF <- chaptersDataFrame[["data"]] chaptersDF <- chaptersDF[chaptersDF$chapter != cahpters[j],] updateProgress() @@ -5681,7 +5806,22 @@ server <- shinyServer(function(input, output, session) { indicator[!is.na(indicator$fullname) & indicator$fullname %in% selectedInd,"chapter"] <- input$chapterNameInput } updateProgress() - kobo_edit_form(survey = survey, indicator = indicator) + + + result <- kobo_edit_form(survey = survey, indicator = indicator) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } + updateProgress() chaptersDF <- chaptersDF[chaptersDF$chapter != selChap,] @@ -5793,7 +5933,22 @@ server <- shinyServer(function(input, output, session) { } updateProgress() - kobo_edit_form(survey = newSurvey) + + + result <- kobo_edit_form(survey = newSurvey) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } + updateProgress() } else if(las == "relabelingChoices"){ @@ -5821,7 +5976,22 @@ server <- shinyServer(function(input, output, session) { mainChoices["labelReport"] <- userRelabelingChoices["labelReport"] - kobo_edit_form(choices = mainChoices) + + + result <- kobo_edit_form(choices = mainChoices) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } + updateProgress() } else if(las == "selectOneType"){ @@ -5872,7 +6042,22 @@ server <- shinyServer(function(input, output, session) { } updateProgress() - kobo_edit_form(survey = newSurvey) + + + result <- kobo_edit_form(survey = newSurvey) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } + } else if(las == "orderOrdinalVariables"){ userChoices <- c() @@ -5926,7 +6111,21 @@ server <- shinyServer(function(input, output, session) { } updateProgress() - kobo_edit_form(choices = newChoices) + + + result <- kobo_edit_form(choices = newChoices) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } } else if(las == "selectMultipleType"){ userSurvey <- sheets[["selectMultipleType"]] @@ -5976,7 +6175,21 @@ server <- shinyServer(function(input, output, session) { } updateProgress() - kobo_edit_form(survey = newSurvey) + + + result <- kobo_edit_form(survey = newSurvey) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } } else if(las == "numericType"){ userSurvey <- sheets[["numericType"]] @@ -6026,7 +6239,22 @@ server <- shinyServer(function(input, output, session) { } updateProgress() - kobo_edit_form(survey = newSurvey) + + result <- kobo_edit_form(survey = newSurvey) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } + + } else if(las == "dateType"){ userSurvey <- sheets[["dateType"]] @@ -6076,7 +6304,21 @@ server <- shinyServer(function(input, output, session) { } updateProgress() - kobo_edit_form(survey = newSurvey) + + + result <- kobo_edit_form(survey = newSurvey) + + if(class(result) == "try-error"){ + shinyalert("Error", + result, + type = "error", + closeOnClickOutside = FALSE, + confirmButtonCol = "#ff4d4d", + animation = FALSE, + showConfirmButton = TRUE + ) + return(FALSE) + } } }, error = function(err) { @@ -6128,7 +6370,7 @@ server <- shinyServer(function(input, output, session) { if("hint" %in% colnames(relabelingSurvey)){ reqNames <- c(reqNames, "hint", "hintReport") - relabelingSurvey[,"hint"] <- as.character(survey[,"hint"]) + relabelingSurvey[,"hint"] <- as.character(relabelingSurvey[,"hint"]) }else{ reqNames <- c(reqNames, "hintReport") } diff --git a/docs/reference/data/dico_form.xls.csv b/docs/reference/data/dico_form.xls.csv index 16a90bc..eea42ff 100644 --- a/docs/reference/data/dico_form.xls.csv +++ b/docs/reference/data/dico_form.xls.csv @@ -1,9 +1,9 @@ -"type","name","fullname","label","labelReport","chapter","disaggregation","correlate","structuralequation.risk","structuralequation.coping","structuralequation.resilience","anonymise","clean","cluster","predict","mappoint","mappoly","listname","qrepeat","qrepeatlabel","qlevel","qgroup","labelchoice","variable","order","weight","score","recategorise","formpart" -"numeric","Sepal.Length","Sepal.Length","Sepal.Length","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","","","household","","","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,"","","","","questions" -"numeric","Sepal.Width","Sepal.Width","Sepal.Width","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","","","household","","","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,"","","","","questions" -"numeric","Petal.Length","Petal.Length","Petal.Length","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","","","household","","","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,"","","","","questions" -"numeric","Petal.Width","Petal.Width","Petal.Width","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","","","household","","","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,"","","","","questions" -"select_one","Species","Species","Species","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","Species_choices","","household","","","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,"","","","","questions" -"select_one_d","setosa","Species.setosa","Species: c(NA, ""setosa"", NA, ""versicolor"", NA, NA, ""virginica"")","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","Species_choices","","household","","","c(NA, ""setosa"", NA, ""versicolor"", NA, NA, ""virginica"")",,"1","","","","answers" -"select_one_d","versicolor","Species.versicolor","Species: c(NA, ""setosa"", NA, ""versicolor"", NA, NA, ""virginica"")","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","Species_choices","","household","","","c(NA, ""setosa"", NA, ""versicolor"", NA, NA, ""virginica"")",,"2","","","","answers" -"select_one_d","virginica","Species.virginica","Species: c(NA, ""setosa"", NA, ""versicolor"", NA, NA, ""virginica"")","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","Species_choices","","household","","","c(NA, ""setosa"", NA, ""versicolor"", NA, NA, ""virginica"")",,"3","","","","answers" +"type","name","fullname","label","labelReport","chapter","disaggregation","correlate","structuralequation.risk","structuralequation.coping","structuralequation.resilience","anonymise","clean","cluster","predict","mappoint","mappoly","relevant","required","constraint","repeat_count","listname","qrepeat","qrepeatlabel","qlevel","qgroup","labelchoice","variable","order","weight","score","recategorise","formpart" +"numeric","Sepal.Length","Sepal.Length","Sepal.Length","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","","","","","","","household","","","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,"","","","","questions" +"numeric","Sepal.Width","Sepal.Width","Sepal.Width","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","","","","","","","household","","","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,"","","","","questions" +"numeric","Petal.Length","Petal.Length","Petal.Length","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","","","","","","","household","","","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,"","","","","questions" +"numeric","Petal.Width","Petal.Width","Petal.Width","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","","","","","","","household","","","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,"","","","","questions" +"select_one","Species","Species","Species","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","","","","","Species_choices","","household","","","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,"","","","","questions" +"select_one_d","setosa","Species.setosa","Species: c(NA, ""setosa"", NA, ""versicolor"", NA, NA, ""virginica"")","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","","","","","Species_choices","","household","","","c(NA, ""setosa"", NA, ""versicolor"", NA, NA, ""virginica"")",,"1","","","","answers" +"select_one_d","versicolor","Species.versicolor","Species: c(NA, ""setosa"", NA, ""versicolor"", NA, NA, ""virginica"")","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","","","","","Species_choices","","household","","","c(NA, ""setosa"", NA, ""versicolor"", NA, NA, ""virginica"")",,"2","","","","answers" +"select_one_d","virginica","Species.virginica","Species: c(NA, ""setosa"", NA, ""versicolor"", NA, NA, ""virginica"")","c(""Sepal.Length"", ""Sepal.Width"", ""Petal.Length"", ""Petal.Width"", ""Species"")",,,,"","","",,"no","","","","","","","","","Species_choices","","household","","","c(NA, ""setosa"", NA, ""versicolor"", NA, NA, ""virginica"")",,"3","","","","answers" diff --git a/docs/reference/format_si.html b/docs/reference/format_si.html index acaacea..cbec0a7 100644 --- a/docs/reference/format_si.html +++ b/docs/reference/format_si.html @@ -96,6 +96,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -179,7 +182,7 @@

    Examp #> trim = TRUE, scientific = FALSE, ...), #> prefix[i]) #> } -#> <environment: 0x564e7c720228>
    +#> <environment: 0x55b4a6d4bc68>

  • diff --git a/docs/reference/index.html b/docs/reference/index.html index cb26fe3..d44b990 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -85,6 +85,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -146,7 +149,7 @@

    kobo_anonymisation_report()

    -

    Generate anonymised dataset

    +

    Generate a report displaying disclosure risk for Statistical Disclosure Control

    @@ -236,7 +239,7 @@

    kobo_cluster_report()

    -

    Generate anonymised dataset

    +

    Generate reports with various clusterisation techniques

    @@ -272,7 +275,7 @@

    kobo_crunching_report()

    -

    crunching Report

    +

    Generate Data Crunching Report

    @@ -302,7 +305,7 @@

    kobo_dico()

    -

    Data dictionnary

    +

    Create Data dictionnary an the xlsform

    @@ -314,7 +317,7 @@

    kobo_edit_form()

    -

    Edit XLS form

    +

    Edit XLS form with shiny app for configuration

    @@ -344,7 +347,7 @@

    kobo_getMainDirectory()

    -

    Main Directory for KoboloadeR package

    +

    get Main Directory for a KoboloadeR project

    @@ -401,6 +404,12 @@

    kobo_left_align()

    + +

    UNHCR ggplot2 theme

    + +

    kobo_load_data()

    @@ -533,10 +542,34 @@

    kobo_unhcr_style_bar()

    + +

    UNHCR ggplot2 theme

    + + + +

    kobo_unhcr_style_histo()

    + +

    UNHCR ggplot2 theme

    + + + +

    kobo_unhcr_style_map()

    + +

    UNHCR ggplot2 theme

    + + + +

    kobo_unhcr_style_scatter()

    + +

    UNHCR ggplot2 theme

    + +

    kobo_weight()

    -

    Weight the data

    +

    Weight a datset

    diff --git a/docs/reference/kobo_anonymisation_report.html b/docs/reference/kobo_anonymisation_report.html index b58084a..d4dcd99 100644 --- a/docs/reference/kobo_anonymisation_report.html +++ b/docs/reference/kobo_anonymisation_report.html @@ -6,7 +6,7 @@ -Generate anonymised dataset — kobo_anonymisation_report • koboloadeR +Generate a report displaying disclosure risk for Statistical Disclosure Control — kobo_anonymisation_report • koboloadeR @@ -30,7 +30,7 @@ - + KoboloadeR Introduction

  • +
  • + Vignette Title +
  • @@ -116,7 +119,7 @@
    diff --git a/docs/reference/kobo_anonymise.html b/docs/reference/kobo_anonymise.html index 694ac89..4e5007c 100644 --- a/docs/reference/kobo_anonymise.html +++ b/docs/reference/kobo_anonymise.html @@ -107,6 +107,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -180,8 +183,7 @@

    Arg

    Examples

    -
    kobo_anonymise()
    #> Error in dico$anonymise: $ operator is invalid for atomic vectors
    -
    # NOT RUN { +
    # NOT RUN {
     kobo_anonymise(frame, dico)
     # }
    diff --git a/docs/reference/kobo_apps.html b/docs/reference/kobo_apps.html index 190d09b..2a59328 100644 --- a/docs/reference/kobo_apps.html +++ b/docs/reference/kobo_apps.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_arrange_variablename.html b/docs/reference/kobo_arrange_variablename.html index 1fd0efe..df06d8e 100644 --- a/docs/reference/kobo_arrange_variablename.html +++ b/docs/reference/kobo_arrange_variablename.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_atlas_report.html b/docs/reference/kobo_atlas_report.html index 6d67802..48e87b8 100644 --- a/docs/reference/kobo_atlas_report.html +++ b/docs/reference/kobo_atlas_report.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_bar_multi.html b/docs/reference/kobo_bar_multi.html index e674855..093dbe0 100644 --- a/docs/reference/kobo_bar_multi.html +++ b/docs/reference/kobo_bar_multi.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_bar_multi_facet.html b/docs/reference/kobo_bar_multi_facet.html index e816e29..3d188b1 100644 --- a/docs/reference/kobo_bar_multi_facet.html +++ b/docs/reference/kobo_bar_multi_facet.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_bar_multi_print.html b/docs/reference/kobo_bar_multi_print.html index eb895a0..85a81e3 100644 --- a/docs/reference/kobo_bar_multi_print.html +++ b/docs/reference/kobo_bar_multi_print.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_bar_one.html b/docs/reference/kobo_bar_one.html index ed63ca2..198475a 100644 --- a/docs/reference/kobo_bar_one.html +++ b/docs/reference/kobo_bar_one.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_bar_one_facet.html b/docs/reference/kobo_bar_one_facet.html index e5420bc..bc0ff2f 100644 --- a/docs/reference/kobo_bar_one_facet.html +++ b/docs/reference/kobo_bar_one_facet.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_bar_one_facet_print.html b/docs/reference/kobo_bar_one_facet_print.html index 3f4c61f..08ef4c5 100644 --- a/docs/reference/kobo_bar_one_facet_print.html +++ b/docs/reference/kobo_bar_one_facet_print.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_bar_one_print.html b/docs/reference/kobo_bar_one_print.html index d126a92..26661a7 100644 --- a/docs/reference/kobo_bar_one_print.html +++ b/docs/reference/kobo_bar_one_print.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_boxplot_facet.html b/docs/reference/kobo_boxplot_facet.html index 6b99b29..f7b2b47 100644 --- a/docs/reference/kobo_boxplot_facet.html +++ b/docs/reference/kobo_boxplot_facet.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_check_analysis_plan.html b/docs/reference/kobo_check_analysis_plan.html index f49569b..3257a12 100644 --- a/docs/reference/kobo_check_analysis_plan.html +++ b/docs/reference/kobo_check_analysis_plan.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_clean.html b/docs/reference/kobo_clean.html index bda3b1c..3ae8d9f 100644 --- a/docs/reference/kobo_clean.html +++ b/docs/reference/kobo_clean.html @@ -91,6 +91,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_cluster_report.html b/docs/reference/kobo_cluster_report.html index 593d2ad..5393914 100644 --- a/docs/reference/kobo_cluster_report.html +++ b/docs/reference/kobo_cluster_report.html @@ -6,7 +6,7 @@ -Generate anonymised dataset — kobo_cluster_report • koboloadeR +Generate reports with various clusterisation techniques — kobo_cluster_report • koboloadeR @@ -30,7 +30,7 @@ - + @@ -89,6 +89,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -115,7 +118,7 @@
    diff --git a/docs/reference/kobo_consolidateone.html b/docs/reference/kobo_consolidateone.html index c4bcc85..5cadae5 100644 --- a/docs/reference/kobo_consolidateone.html +++ b/docs/reference/kobo_consolidateone.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_correlation.html b/docs/reference/kobo_correlation.html index 413e753..373c50a 100644 --- a/docs/reference/kobo_correlation.html +++ b/docs/reference/kobo_correlation.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_correlation_analysis.html b/docs/reference/kobo_correlation_analysis.html index c786081..675e15a 100644 --- a/docs/reference/kobo_correlation_analysis.html +++ b/docs/reference/kobo_correlation_analysis.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_corrplot.html b/docs/reference/kobo_corrplot.html index 82deeaf..e9dabc5 100644 --- a/docs/reference/kobo_corrplot.html +++ b/docs/reference/kobo_corrplot.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_create_indicators.html b/docs/reference/kobo_create_indicators.html index b74c489..b19acf4 100644 --- a/docs/reference/kobo_create_indicators.html +++ b/docs/reference/kobo_create_indicators.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -473,8 +476,7 @@

    Examp #> rpart.plot Plot 'rpart' Models: An Enhanced Version of 'plot.rpart' #> sampling Survey Sampling #> scales Scale Functions for Visualization -#> sdcMicro Statistical Disclosure Control Methods for Anonymization of -#> +#> sdcMicro Statistical Disclosure Control Methods for Anonymization of #> sp Classes and Methods for Spatial Data #> stringdist Approximate String Matching and String Distance Functions #> stringi Character String Processing Facilities @@ -516,9 +518,7 @@

    Examp #> #> viridis_pal
    #> The following object is masked from ‘package:readr’: #> -#> col_factor
    #> Registered S3 method overwritten by 'rvest': -#> method from -#> read_xml.response xml2
    #> +#> col_factor
    #> #> Attaching package: ‘kableExtra’
    #> The following object is masked from ‘package:dplyr’: #> #> group_rows
    #> Loading required package: sylly
    #> diff --git a/docs/reference/kobo_crunching_report.html b/docs/reference/kobo_crunching_report.html index 153d067..88e221e 100644 --- a/docs/reference/kobo_crunching_report.html +++ b/docs/reference/kobo_crunching_report.html @@ -6,7 +6,7 @@ -crunching Report — kobo_crunching_report • koboloadeR +Generate Data Crunching Report — kobo_crunching_report • koboloadeR @@ -30,7 +30,7 @@ - + @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -114,7 +117,7 @@
    @@ -477,8 +480,7 @@

    Examp #> rpart.plot Plot 'rpart' Models: An Enhanced Version of 'plot.rpart' #> sampling Survey Sampling #> scales Scale Functions for Visualization -#> sdcMicro Statistical Disclosure Control Methods for Anonymization of -#> +#> sdcMicro Statistical Disclosure Control Methods for Anonymization of #> sp Classes and Methods for Spatial Data #> stringdist Approximate String Matching and String Distance Functions #> stringi Character String Processing Facilities @@ -502,7 +504,7 @@

    Examp #> #> #> -#> Loading data. It is assumed that the cleaning, weighting & re-encoding has been done previously

    #> Warning: cannot open file '/home/edouard/R-project/koboloadeR-ghpages/docs/reference/data/MainDataFrame.csv': No such file or directory
    #> [1] "kobo_crunching_report_ERROR"
    #> $message +#> Loading data. It is assumed that the cleaning, weighting & re-encoding has been done previously
    #> Warning: cannot open file '/home/edouard/R-project/koboloadeR-ghpages/docs/reference/data/MainDataFrame-encoded.csv': No such file or directory
    #> [1] "kobo_crunching_report_ERROR"
    #> $message #> [1] "cannot open the connection" #> #> $call diff --git a/docs/reference/kobo_data_downloader.html b/docs/reference/kobo_data_downloader.html index 32ea06c..ea87ab9 100644 --- a/docs/reference/kobo_data_downloader.html +++ b/docs/reference/kobo_data_downloader.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_datasets.html b/docs/reference/kobo_datasets.html index 110b298..fae92db 100644 --- a/docs/reference/kobo_datasets.html +++ b/docs/reference/kobo_datasets.html @@ -89,6 +89,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_datasets2.html b/docs/reference/kobo_datasets2.html index 34e9d95..93ad3af 100644 --- a/docs/reference/kobo_datasets2.html +++ b/docs/reference/kobo_datasets2.html @@ -89,6 +89,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_ddi.html b/docs/reference/kobo_ddi.html index 0a39293..02ee406 100644 --- a/docs/reference/kobo_ddi.html +++ b/docs/reference/kobo_ddi.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_dico.html b/docs/reference/kobo_dico.html index bd8569c..a8bcc5a 100644 --- a/docs/reference/kobo_dico.html +++ b/docs/reference/kobo_dico.html @@ -6,7 +6,7 @@ -Data dictionnary — kobo_dico • koboloadeR +Create Data dictionnary an the xlsform — kobo_dico • koboloadeR @@ -30,7 +30,7 @@ - + @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -114,7 +117,7 @@
    @@ -161,7 +164,29 @@

    Examp #> 8- No column `cluster` in your survey worksheet. Creating a dummy one for the moment (see readme file). ... #> 9- No column `predict` in your survey worksheet. Creating a dummy one for the moment (see readme file). ... #> 10- No column `mappoint` in your survey worksheet. Creating a dummy one for the moment (see readme file). ... -#> 11- No column `mappoly` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...

    #> Error: Can't find columns `relevant`, `required`, `constraint`, `repeat_count` in `.data`.
    +#> 11- No column `mappoly` in your survey worksheet. Creating a dummy one for the moment (see readme file). ... +#> 1- No column `relevant` in your survey worksheet. Creating a dummy one for the moment... +#> 1- No column `required` in your survey worksheet. Creating a dummy one for the moment... +#> 1- No column `constraint` in your survey worksheet. Creating a dummy one for the moment... +#> 1- No column `repeat_count` in your survey worksheet. Creating a dummy one for the moment... +#> +#> Now extracting list name from questions type. +#> +#> +#> Be careful! The current function only support 2 levels of nested repeat - for instance household / Case / Individual. +#> +#> +#> Now rebuilding the variable full path in order to match with variable name from the exported dataset. +#> +#> Note that there should not be any dots in the orginal variables. +#> +#> Double Check as well there's no duplicate for the name column in the survey worksheet +#> +#> No column `labelReport` in your `choices` worksheet. Creating a dummy one for the moment... +#> Good: You have a column `order` in your `choices` worksheet. +#> No column `weight` in your `choices` worksheet. Creating a dummy one for the moment... +#> No column `recategorise` in your `choices` worksheet. Creating a dummy one for the moment... +#> No column `score` in your `choices` worksheet. Creating a dummy one for the moment...
    # NOT RUN { kobo_dico("myform.xls") # }
    diff --git a/docs/reference/kobo_dummy.html b/docs/reference/kobo_dummy.html index d8a07b8..f8efa15 100644 --- a/docs/reference/kobo_dummy.html +++ b/docs/reference/kobo_dummy.html @@ -97,6 +97,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -174,7 +177,38 @@

    Examp #> 8- No column `cluster` in your survey worksheet. Creating a dummy one for the moment (see readme file). ... #> 9- No column `predict` in your survey worksheet. Creating a dummy one for the moment (see readme file). ... #> 10- No column `mappoint` in your survey worksheet. Creating a dummy one for the moment (see readme file). ... -#> 11- No column `mappoly` in your survey worksheet. Creating a dummy one for the moment (see readme file). ...
    #> Error: Can't find columns `relevant`, `required`, `constraint`, `repeat_count` in `.data`.
    +#> 11- No column `mappoly` in your survey worksheet. Creating a dummy one for the moment (see readme file). ... +#> 1- No column `relevant` in your survey worksheet. Creating a dummy one for the moment... +#> 1- No column `required` in your survey worksheet. Creating a dummy one for the moment... +#> 1- No column `constraint` in your survey worksheet. Creating a dummy one for the moment... +#> 1- No column `repeat_count` in your survey worksheet. Creating a dummy one for the moment... +#> +#> Now extracting list name from questions type. +#> +#> +#> Be careful! The current function only support 2 levels of nested repeat - for instance household / Case / Individual. +#> +#> +#> Now rebuilding the variable full path in order to match with variable name from the exported dataset. +#> +#> Note that there should not be any dots in the orginal variables. +#> +#> Double Check as well there's no duplicate for the name column in the survey worksheet +#> +#> No column `labelReport` in your `choices` worksheet. Creating a dummy one for the moment... +#> Good: You have a column `order` in your `choices` worksheet. +#> No column `weight` in your `choices` worksheet. Creating a dummy one for the moment... +#> No column `recategorise` in your `choices` worksheet. Creating a dummy one for the moment... +#> No column `score` in your `choices` worksheet. Creating a dummy one for the moment... +#> Sepal.Length / bound = NA / relevant = NA +#> Sepal.Width / bound = NA / relevant = NA +#> Petal.Length / bound = NA / relevant = NA +#> Petal.Width / bound = NA / relevant = NA +#> Species / bound = NA / relevant = NA +#> setosa / bound = NA / relevant = NA +#> versicolor / bound = NA / relevant = NA +#> virginica / bound = NA / relevant = NA
    #> Warning: object 'detecthigh' not found
    #> Warning: object 'detecthighzero' not found
    #> Warning: object 'detectlow' not found
    #> Warning: object 'detectlowzero' not found
    #> Warning: object 'detectrelevant1' not found
    #> Warning: object 'detectrelevant2' not found
    #> Warning: object 'detectrelevant3' not found
    #> Generating household tableEntering summy data for variable 1- Sepal.Length / numeric / +#> Rename variableSepal.Length
    #> Error in names(dummydata)[i + 1] <- fullname: 'names' attribute [2] must be the same length as the vector [1]
    # NOT RUN { kobo_dummy(form) # }
    diff --git a/docs/reference/kobo_edit_form.html b/docs/reference/kobo_edit_form.html index 3fee7e8..906c6e8 100644 --- a/docs/reference/kobo_edit_form.html +++ b/docs/reference/kobo_edit_form.html @@ -6,7 +6,7 @@ -Edit XLS form — kobo_edit_form • koboloadeR +Edit XLS form with shiny app for configuration — kobo_edit_form • koboloadeR @@ -30,7 +30,7 @@ - + @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -114,7 +117,7 @@
    @@ -126,7 +129,7 @@

    Edit XLS form

    kobo_edit_form(form = "form.xls", survey = NULL, choices = NULL,
    -  indicator = NULL, settings = NULL)
    + indicator = NULL, settings = NULL, analysisSettings = NULL)

    Arguments

    @@ -152,6 +155,10 @@

    Arg

    + + + +
    settings

    Dataframe that represent the data of settings sheet in the xlsform

    analysisSettings

    Dataframe that represent the data of analysisSettings sheet in the xlsform

    Value

    @@ -160,7 +167,7 @@

    Value

    Examples

    -
    kobo_edit_form()
    #> Workbook has no sheets!
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    +
    kobo_edit_form()
    #> Workbook has no sheets!
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    #> Warning: no non-missing arguments to max; returning -Inf
    # NOT RUN { kobo_edit_form("myform.xls") # }
    diff --git a/docs/reference/kobo_encode.html b/docs/reference/kobo_encode.html index ee89796..bb7aeda 100644 --- a/docs/reference/kobo_encode.html +++ b/docs/reference/kobo_encode.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_encode_repeat.html b/docs/reference/kobo_encode_repeat.html index 748b7ef..e0dc734 100644 --- a/docs/reference/kobo_encode_repeat.html +++ b/docs/reference/kobo_encode_repeat.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_form.html b/docs/reference/kobo_form.html index d929c2d..b5fea2e 100644 --- a/docs/reference/kobo_form.html +++ b/docs/reference/kobo_form.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_forminfo.html b/docs/reference/kobo_forminfo.html index 0968d20..be03705 100644 --- a/docs/reference/kobo_forminfo.html +++ b/docs/reference/kobo_forminfo.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_getMainDirectory.html b/docs/reference/kobo_getMainDirectory.html index 0d66d23..0d58add 100644 --- a/docs/reference/kobo_getMainDirectory.html +++ b/docs/reference/kobo_getMainDirectory.html @@ -6,7 +6,7 @@ -Main Directory for KoboloadeR package — kobo_getMainDirectory • koboloadeR +get Main Directory for a KoboloadeR project — kobo_getMainDirectory • koboloadeR @@ -30,7 +30,7 @@ - + @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -114,7 +117,7 @@
    @@ -483,8 +486,7 @@

    Examp #> rpart.plot Plot 'rpart' Models: An Enhanced Version of 'plot.rpart' #> sampling Survey Sampling #> scales Scale Functions for Visualization -#> sdcMicro Statistical Disclosure Control Methods for Anonymization of -#> +#> sdcMicro Statistical Disclosure Control Methods for Anonymization of #> sp Classes and Methods for Spatial Data #> stringdist Approximate String Matching and String Distance Functions #> stringi Character String Processing Facilities diff --git a/docs/reference/kobo_get_begin_repeat.html b/docs/reference/kobo_get_begin_repeat.html index 827cbb9..b7867b0 100644 --- a/docs/reference/kobo_get_begin_repeat.html +++ b/docs/reference/kobo_get_begin_repeat.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_get_config.html b/docs/reference/kobo_get_config.html index 44cd21d..dc4cf8b 100644 --- a/docs/reference/kobo_get_config.html +++ b/docs/reference/kobo_get_config.html @@ -32,7 +32,7 @@ - + @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -121,7 +124,7 @@

    Get Configuration

    -

    Return all configuration from settings sheet of xlsform

    +

    Return all configuration from Analysis Settings sheet of xlsform

    diff --git a/docs/reference/kobo_get_dataframes_levels.html b/docs/reference/kobo_get_dataframes_levels.html index 580589a..deb301d 100644 --- a/docs/reference/kobo_get_dataframes_levels.html +++ b/docs/reference/kobo_get_dataframes_levels.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_get_theme.html b/docs/reference/kobo_get_theme.html index 66f618c..2eb79ee 100644 --- a/docs/reference/kobo_get_theme.html +++ b/docs/reference/kobo_get_theme.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -125,7 +128,7 @@

    Get Themes

    -
    kobo_get_theme(form = "form.xls")
    +
    kobo_get_theme()

    Value

    diff --git a/docs/reference/kobo_histo.html b/docs/reference/kobo_histo.html index 9f4da55..3eac064 100644 --- a/docs/reference/kobo_histo.html +++ b/docs/reference/kobo_histo.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_histo_print.html b/docs/reference/kobo_histo_print.html index 2a93b2a..1613362 100644 --- a/docs/reference/kobo_histo_print.html +++ b/docs/reference/kobo_histo_print.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_host.html b/docs/reference/kobo_host.html index 9fdc401..8c80842 100644 --- a/docs/reference/kobo_host.html +++ b/docs/reference/kobo_host.html @@ -89,6 +89,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_indicator.html b/docs/reference/kobo_indicator.html index 4116e88..ed158c3 100644 --- a/docs/reference/kobo_indicator.html +++ b/docs/reference/kobo_indicator.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_label.html b/docs/reference/kobo_label.html index c55d7ee..c223d58 100644 --- a/docs/reference/kobo_label.html +++ b/docs/reference/kobo_label.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_left_align.html b/docs/reference/kobo_left_align.html new file mode 100644 index 0000000..b104ac5 --- /dev/null +++ b/docs/reference/kobo_left_align.html @@ -0,0 +1,171 @@ + + + + + + + + +UNHCR ggplot2 theme — kobo_left_align • koboloadeR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + +
    + +

    Left align chart title and subtitle on a ggplot2

    + +
    + +
    kobo_left_align(plot_name, pieces)
    + +

    Value

    + +

    Return better chart

    + + +

    Examples

    +
    kobo_left_align()
    #> Error in ggplot_build(x): argument "plot_name" is missing, with no default
    +
    +
    + +
    + + +
    + + + + + + diff --git a/docs/reference/kobo_load_data.html b/docs/reference/kobo_load_data.html index 1ef00a4..b35b93d 100644 --- a/docs/reference/kobo_load_data.html +++ b/docs/reference/kobo_load_data.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -477,8 +480,7 @@

    Examp #> rpart.plot Plot 'rpart' Models: An Enhanced Version of 'plot.rpart' #> sampling Survey Sampling #> scales Scale Functions for Visualization -#> sdcMicro Statistical Disclosure Control Methods for Anonymization of -#> +#> sdcMicro Statistical Disclosure Control Methods for Anonymization of #> sp Classes and Methods for Spatial Data #> stringdist Approximate String Matching and String Distance Functions #> stringi Character String Processing Facilities @@ -503,6 +505,13 @@

    Examp #> #> #> +#> Getting project configuration variables +#> +#> +#> +#> +#> +#> #> Generate dictionnary from the xlsform #> #> @@ -526,65 +535,45 @@

    Examp #> 9- No column `predict` in your survey worksheet. Creating a dummy one for the moment (see readme file). ... #> 10- No column `mappoint` in your survey worksheet. Creating a dummy one for the moment (see readme file). ... #> 11- No column `mappoly` in your survey worksheet. Creating a dummy one for the moment (see readme file). ... +#> 1- No column `relevant` in your survey worksheet. Creating a dummy one for the moment... +#> 1- No column `required` in your survey worksheet. Creating a dummy one for the moment... +#> 1- No column `constraint` in your survey worksheet. Creating a dummy one for the moment... +#> 1- No column `repeat_count` in your survey worksheet. Creating a dummy one for the moment... +#> +#> Now extracting list name from questions type. +#> +#> +#> Be careful! The current function only support 2 levels of nested repeat - for instance household / Case / Individual. +#> +#> +#> Now rebuilding the variable full path in order to match with variable name from the exported dataset. +#> +#> Note that there should not be any dots in the orginal variables. +#> +#> Double Check as well there's no duplicate for the name column in the survey worksheet +#> +#> No column `labelReport` in your `choices` worksheet. Creating a dummy one for the moment... +#> Good: You have a column `order` in your `choices` worksheet. +#> No column `weight` in your `choices` worksheet. Creating a dummy one for the moment... +#> No column `recategorise` in your `choices` worksheet. Creating a dummy one for the moment... +#> No column `score` in your `choices` worksheet. Creating a dummy one for the moment... +#> +#> +#> +#> Load original dataset +#> +#> +#> #> [1] "kobo_load_data_ERROR"
    #> $message -#> [1] "Can't find columns `relevant`, `required`, `constraint`, `repeat_count` in `.data`." -#> -#> $trace -#> █ -#> 1. ├─base::tryCatch(...) -#> 2. │ └─base:::tryCatchList(expr, classes, parentenv, handlers) -#> 3. │ ├─base:::tryCatchOne(...) -#> 4. │ │ └─base:::doTryCatch(return(expr), name, parentenv, handler) -#> 5. │ └─base:::tryCatchList(expr, names[-nh], parentenv, handlers[-nh]) -#> 6. │ └─base:::tryCatchOne(expr, names, parentenv, handlers[[1L]]) -#> 7. │ └─base:::doTryCatch(return(expr), name, parentenv, handler) -#> 8. ├─base::withCallingHandlers(...) -#> 9. ├─base::saveRDS(...) -#> 10. ├─base::do.call(...) -#> 11. ├─(function (what, args, quote = FALSE, envir = parent.frame()) ... -#> 12. └─(function (..., crayon_enabled, crayon_colors, pkgdown_internet) ... -#> 13. └─pkgdown::build_site(...) -#> 14. └─pkgdown:::build_site_local(...) -#> 15. └─pkgdown::build_reference(...) -#> 16. └─purrr::map(...) -#> 17. └─pkgdown:::.f(.x[[i]], ...) -#> 18. └─pkgdown:::data_reference_topic(...) -#> 19. ├─pkgdown:::as_data(...) -#> 20. └─pkgdown:::as_data.tag_examples(...) -#> 21. └─purrr::pmap_chr(...) -#> 22. └─pkgdown:::.f(...) -#> 23. ├─withr::with_options(...) -#> 24. │ └─base::force(code) -#> 25. └─evaluate::evaluate(code, env, new_device = TRUE) -#> 26. └─evaluate:::evaluate_call(...) -#> 27. ├─evaluate:::timing_fn(...) -#> 28. ├─evaluate:::handle(...) -#> 29. │ └─base::try(f, silent = TRUE) -#> 30. │ └─base::tryCatch(...) -#> 31. │ └─base:::tryCatchList(expr, classes, parentenv, handlers) -#> 32. │ └─base:::tryCatchOne(expr, names, parentenv, handlers[[1L]]) -#> 33. │ └─base:::doTryCatch(return(expr), name, parentenv, handler) -#> 34. ├─base::withCallingHandlers(...) -#> 35. ├─base::withVisible(eval(expr, envir, enclos)) -#> 36. └─base::eval(expr, envir, enclos) -#> 37. └─base::eval(expr, envir, enclos) -#> 38. └─koboloadeR::kobo_load_data() -#> 39. ├─base::tryCatch(...) /home/edouard/R-project/koboloadeR-ghpages/R/kobo_load_data.R:28:2 -#> 40. │ └─base:::tryCatchList(expr, classes, parentenv, handlers) -#> 41. │ └─base:::tryCatchOne(expr, names, parentenv, handlers[[1L]]) -#> 42. │ └─base:::doTryCatch(return(expr), name, parentenv, handler) -#> 43. └─koboloadeR::kobo_dico(form) /home/edouard/R-project/koboloadeR-ghpages/R/kobo_load_data.R:50:4 -#> 44. ├─...[] /home/edouard/R-project/koboloadeR-ghpages/R/kobo_dico.R:148:2 -#> 45. └─tibble:::`[.tbl_df`(...) /home/edouard/R-project/koboloadeR-ghpages/R/kobo_dico.R:148:2 -#> 46. └─tibble:::check_names_df(j, x) -#> 47. └─tibble:::check_names_before_after_character(j, names(unclass(x))) -#> -#> $parent -#> NULL +#> [1] "'file' must be a character string or connection" +#> +#> $call +#> read.table(file = file, header = header, sep = sep, quote = quote, +#> dec = dec, fill = fill, comment.char = comment.char, ...) #> #> attr(,"class") #> [1] "try-error"
    -
    # NOT RUN { +# NOT RUN { kobo_load_data("myform.xls") # }
    diff --git a/docs/reference/kobo_load_packages.html b/docs/reference/kobo_load_packages.html index 6d36f80..b097087 100644 --- a/docs/reference/kobo_load_packages.html +++ b/docs/reference/kobo_load_packages.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -463,8 +466,7 @@

    Examp #> rpart.plot Plot 'rpart' Models: An Enhanced Version of 'plot.rpart' #> sampling Survey Sampling #> scales Scale Functions for Visualization -#> sdcMicro Statistical Disclosure Control Methods for Anonymization of -#> +#> sdcMicro Statistical Disclosure Control Methods for Anonymization of #> sp Classes and Methods for Spatial Data #> stringdist Approximate String Matching and String Distance Functions #> stringi Character String Processing Facilities diff --git a/docs/reference/kobo_map_cat.html b/docs/reference/kobo_map_cat.html index 67bb3fa..f34d557 100644 --- a/docs/reference/kobo_map_cat.html +++ b/docs/reference/kobo_map_cat.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_map_int.html b/docs/reference/kobo_map_int.html index c5bafbe..f89943e 100644 --- a/docs/reference/kobo_map_int.html +++ b/docs/reference/kobo_map_int.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_prediction_report.html b/docs/reference/kobo_prediction_report.html index 676a57c..57b8506 100644 --- a/docs/reference/kobo_prediction_report.html +++ b/docs/reference/kobo_prediction_report.html @@ -101,6 +101,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_prepare_form.html b/docs/reference/kobo_prepare_form.html index f8149b7..46b5ff0 100644 --- a/docs/reference/kobo_prepare_form.html +++ b/docs/reference/kobo_prepare_form.html @@ -90,6 +90,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -150,11 +153,14 @@

    Examp
    kobo_prepare_form()
    #> #> Your form should be placed within the `data` folder. #> +#> ################################# +#> ### Checking now survey sheet ## +#> ################################# #> Checking now for additional information within your xlsform. Note that you can insert them in the xls and re-run the function! #> -#> No column `labelReport` in your survey worksheet. Creating a dummy one for the moment (see readme file). ... +#> No column `labelReport` in your survey worksheet. Creating a dummy one for the moment based on the initial one - trimmed to 80 characters (see readme file). ... #> No column `hintReport` in your survey worksheet. Creating a dummy one for the moment (see readme file). ... -#> [1] "kobo_prepare_form_ERROR"
    #> $message +#> [1] "There was an error in the xlsform preparation"
    #> $message #> [1] "undefined columns selected" #> #> $call diff --git a/docs/reference/kobo_projectconfig.html b/docs/reference/kobo_projectconfig.html index 2fa6b81..00e9a0d 100644 --- a/docs/reference/kobo_projectconfig.html +++ b/docs/reference/kobo_projectconfig.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_projectinit.html b/docs/reference/kobo_projectinit.html index 5c0d231..d2ef6d4 100644 --- a/docs/reference/kobo_projectinit.html +++ b/docs/reference/kobo_projectinit.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -483,8 +486,7 @@

    Examp #> rpart.plot Plot 'rpart' Models: An Enhanced Version of 'plot.rpart' #> sampling Survey Sampling #> scales Scale Functions for Visualization -#> sdcMicro Statistical Disclosure Control Methods for Anonymization of -#> +#> sdcMicro Statistical Disclosure Control Methods for Anonymization of #> sp Classes and Methods for Spatial Data #> stringdist Approximate String Matching and String Distance Functions #> stringi Character String Processing Facilities diff --git a/docs/reference/kobo_question.html b/docs/reference/kobo_question.html index 3499dce..8fc149e 100644 --- a/docs/reference/kobo_question.html +++ b/docs/reference/kobo_question.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_registration.html b/docs/reference/kobo_registration.html index 7262a13..865296a 100644 --- a/docs/reference/kobo_registration.html +++ b/docs/reference/kobo_registration.html @@ -127,6 +127,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_rename_xlsform_dataframes.html b/docs/reference/kobo_rename_xlsform_dataframes.html index ed31d18..4d1d4a0 100644 --- a/docs/reference/kobo_rename_xlsform_dataframes.html +++ b/docs/reference/kobo_rename_xlsform_dataframes.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_samplingframe.html b/docs/reference/kobo_samplingframe.html index de36659..44b64de 100644 --- a/docs/reference/kobo_samplingframe.html +++ b/docs/reference/kobo_samplingframe.html @@ -92,6 +92,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_shiny.html b/docs/reference/kobo_shiny.html index d85416a..3e836d0 100644 --- a/docs/reference/kobo_shiny.html +++ b/docs/reference/kobo_shiny.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_split_multiple.html b/docs/reference/kobo_split_multiple.html index 80818d0..6a446c6 100644 --- a/docs/reference/kobo_split_multiple.html +++ b/docs/reference/kobo_split_multiple.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_submission_count.html b/docs/reference/kobo_submission_count.html index cd71dde..634cf6c 100644 --- a/docs/reference/kobo_submission_count.html +++ b/docs/reference/kobo_submission_count.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_surveyname.html b/docs/reference/kobo_surveyname.html index 1ddf756..3c95e0c 100644 --- a/docs/reference/kobo_surveyname.html +++ b/docs/reference/kobo_surveyname.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_text_cloud.html b/docs/reference/kobo_text_cloud.html index 9d75c3e..e49e75f 100644 --- a/docs/reference/kobo_text_cloud.html +++ b/docs/reference/kobo_text_cloud.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_time_parser.html b/docs/reference/kobo_time_parser.html index dffbecc..8a048df 100644 --- a/docs/reference/kobo_time_parser.html +++ b/docs/reference/kobo_time_parser.html @@ -90,6 +90,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_time_parser_UTC.html b/docs/reference/kobo_time_parser_UTC.html index f01fcf2..4635848 100644 --- a/docs/reference/kobo_time_parser_UTC.html +++ b/docs/reference/kobo_time_parser_UTC.html @@ -90,6 +90,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_to_xlsform.html b/docs/reference/kobo_to_xlsform.html index 59cf742..81fcad1 100644 --- a/docs/reference/kobo_to_xlsform.html +++ b/docs/reference/kobo_to_xlsform.html @@ -92,6 +92,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_trend.html b/docs/reference/kobo_trend.html index 291d100..af7ea08 100644 --- a/docs/reference/kobo_trend.html +++ b/docs/reference/kobo_trend.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_trend_report.html b/docs/reference/kobo_trend_report.html index 57ae31c..dc031f7 100644 --- a/docs/reference/kobo_trend_report.html +++ b/docs/reference/kobo_trend_report.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/kobo_unhcr_style_bar.html b/docs/reference/kobo_unhcr_style_bar.html new file mode 100644 index 0000000..6704ae3 --- /dev/null +++ b/docs/reference/kobo_unhcr_style_bar.html @@ -0,0 +1,293 @@ + + + + + + + + +UNHCR ggplot2 theme — kobo_unhcr_style_bar • koboloadeR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + +
    + +

    Return ggplot2 styling for bar chart

    + +
    + +
    kobo_unhcr_style_bar()
    + +

    Value

    + +

    Return UNHCR Style

    + + +

    Examples

    +
    kobo_unhcr_style_bar()
    #> List of 20 +#> $ axis.title : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ axis.text :List of 11 +#> ..$ family : chr "Lato" +#> ..$ face : NULL +#> ..$ colour : chr "#222222" +#> ..$ size : num 11 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ axis.text.x :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : NULL +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] 5pt 0pt 9pt 0pt +#> .. ..- attr(*, "valid.unit")= int 8 +#> .. ..- attr(*, "unit")= chr "pt" +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ axis.ticks : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ axis.line : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.background : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.key : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.text :List of 11 +#> ..$ family : chr "Lato" +#> ..$ face : NULL +#> ..$ colour : chr "#222222" +#> ..$ size : num 9 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ legend.text.align : num 0 +#> $ legend.title : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.position : chr "top" +#> $ panel.background : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ panel.grid.minor : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ panel.grid.major.x:List of 6 +#> ..$ colour : chr "#cbcbcb" +#> ..$ size : NULL +#> ..$ linetype : NULL +#> ..$ lineend : NULL +#> ..$ arrow : logi FALSE +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_line" "element" +#> $ panel.grid.major.y: list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ plot.title :List of 11 +#> ..$ family : chr "Lato" +#> ..$ face : chr "bold" +#> ..$ colour : chr "#222222" +#> ..$ size : num 12 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ plot.subtitle :List of 11 +#> ..$ family : chr "Lato" +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : num 11 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] 9pt 0pt 9pt 0pt +#> .. ..- attr(*, "valid.unit")= int 8 +#> .. ..- attr(*, "unit")= chr "pt" +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ plot.caption : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ strip.background :List of 5 +#> ..$ fill : chr "white" +#> ..$ colour : NULL +#> ..$ size : NULL +#> ..$ linetype : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_rect" "element" +#> $ strip.text :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : num 11 +#> ..$ hjust : num 0 +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> - attr(*, "class")= chr [1:2] "theme" "gg" +#> - attr(*, "complete")= logi FALSE +#> - attr(*, "validate")= logi TRUE
    +
    +
    + +
    + +
    + + +
    +

    Site built with pkgdown 1.3.0.

    +
    +
    +
    + + + + + + diff --git a/docs/reference/kobo_unhcr_style_histo.html b/docs/reference/kobo_unhcr_style_histo.html new file mode 100644 index 0000000..a722ba1 --- /dev/null +++ b/docs/reference/kobo_unhcr_style_histo.html @@ -0,0 +1,293 @@ + + + + + + + + +UNHCR ggplot2 theme — kobo_unhcr_style_histo • koboloadeR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + +
    + +

    Return ggplot2 styling for histogram

    + +
    + +
    kobo_unhcr_style_histo()
    + +

    Value

    + +

    Return UNHCR Style

    + + +

    Examples

    +
    kobo_unhcr_style_histo()
    #> List of 20 +#> $ axis.title : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ axis.text :List of 11 +#> ..$ family : chr "Lato" +#> ..$ face : NULL +#> ..$ colour : chr "#222222" +#> ..$ size : num 11 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ axis.text.x :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : NULL +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] 5pt 0pt 9pt 0pt +#> .. ..- attr(*, "valid.unit")= int 8 +#> .. ..- attr(*, "unit")= chr "pt" +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ axis.ticks : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ axis.line : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.background : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.key : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.text :List of 11 +#> ..$ family : chr "Lato" +#> ..$ face : NULL +#> ..$ colour : chr "#222222" +#> ..$ size : num 9 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ legend.text.align : num 0 +#> $ legend.title : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.position : chr "top" +#> $ panel.background : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ panel.grid.minor : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ panel.grid.major.x: list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ panel.grid.major.y:List of 6 +#> ..$ colour : chr "#cbcbcb" +#> ..$ size : NULL +#> ..$ linetype : NULL +#> ..$ lineend : NULL +#> ..$ arrow : logi FALSE +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_line" "element" +#> $ plot.title :List of 11 +#> ..$ family : chr "Lato" +#> ..$ face : chr "bold" +#> ..$ colour : chr "#222222" +#> ..$ size : num 12 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ plot.subtitle :List of 11 +#> ..$ family : chr "Lato" +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : num 11 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] 9pt 0pt 9pt 0pt +#> .. ..- attr(*, "valid.unit")= int 8 +#> .. ..- attr(*, "unit")= chr "pt" +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ plot.caption : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ strip.background :List of 5 +#> ..$ fill : chr "white" +#> ..$ colour : NULL +#> ..$ size : NULL +#> ..$ linetype : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_rect" "element" +#> $ strip.text :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : num 11 +#> ..$ hjust : num 0 +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> - attr(*, "class")= chr [1:2] "theme" "gg" +#> - attr(*, "complete")= logi FALSE +#> - attr(*, "validate")= logi TRUE
    +
    +
    + +
    + +
    + + +
    +

    Site built with pkgdown 1.3.0.

    +
    +
    +
    + + + + + + diff --git a/docs/reference/kobo_unhcr_style_map.html b/docs/reference/kobo_unhcr_style_map.html new file mode 100644 index 0000000..d0a47d2 --- /dev/null +++ b/docs/reference/kobo_unhcr_style_map.html @@ -0,0 +1,486 @@ + + + + + + + + +UNHCR ggplot2 theme — kobo_unhcr_style_map • koboloadeR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + +
    + +

    Return ggplot2 styling for maps

    + +
    + +
    kobo_unhcr_style_map()
    + +

    Value

    + +

    Return UNHCR Style

    + + +

    Examples

    +
    kobo_unhcr_style_map()
    #> List of 60 +#> $ line :List of 6 +#> ..$ colour : chr "black" +#> ..$ size : num 0.5 +#> ..$ linetype : num 1 +#> ..$ lineend : chr "butt" +#> ..$ arrow : logi FALSE +#> ..$ inherit.blank: logi TRUE +#> ..- attr(*, "class")= chr [1:2] "element_line" "element" +#> $ rect :List of 5 +#> ..$ fill : chr "white" +#> ..$ colour : chr "black" +#> ..$ size : num 0.5 +#> ..$ linetype : num 1 +#> ..$ inherit.blank: logi TRUE +#> ..- attr(*, "class")= chr [1:2] "element_rect" "element" +#> $ text :List of 11 +#> ..$ family : chr "" +#> ..$ face : chr "plain" +#> ..$ colour : chr "black" +#> ..$ size : num 11 +#> ..$ hjust : num 0.5 +#> ..$ vjust : num 0.5 +#> ..$ angle : num 0 +#> ..$ lineheight : num 0.9 +#> ..$ margin : 'margin' num [1:4] 0pt 0pt 0pt 0pt +#> .. ..- attr(*, "valid.unit")= int 8 +#> .. ..- attr(*, "unit")= chr "pt" +#> ..$ debug : logi FALSE +#> ..$ inherit.blank: logi TRUE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ axis.title.x : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ axis.title.x.top :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : NULL +#> ..$ hjust : NULL +#> ..$ vjust : num 0 +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] 0pt 0pt 2.75pt 0pt +#> .. ..- attr(*, "valid.unit")= int 8 +#> .. ..- attr(*, "unit")= chr "pt" +#> ..$ debug : NULL +#> ..$ inherit.blank: logi TRUE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ axis.title.y : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ axis.title.y.right :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : NULL +#> ..$ hjust : NULL +#> ..$ vjust : num 0 +#> ..$ angle : num -90 +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] 0pt 0pt 0pt 2.75pt +#> .. ..- attr(*, "valid.unit")= int 8 +#> .. ..- attr(*, "unit")= chr "pt" +#> ..$ debug : NULL +#> ..$ inherit.blank: logi TRUE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ axis.text :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : chr "grey30" +#> ..$ size : 'rel' num 0.8 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi TRUE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ axis.text.x : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ axis.text.x.top :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : NULL +#> ..$ hjust : NULL +#> ..$ vjust : num 0 +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] 0pt 0pt 2.2pt 0pt +#> .. ..- attr(*, "valid.unit")= int 8 +#> .. ..- attr(*, "unit")= chr "pt" +#> ..$ debug : NULL +#> ..$ inherit.blank: logi TRUE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ axis.text.y : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ axis.text.y.right :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : NULL +#> ..$ hjust : num 0 +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] 0pt 0pt 0pt 2.2pt +#> .. ..- attr(*, "valid.unit")= int 8 +#> .. ..- attr(*, "unit")= chr "pt" +#> ..$ debug : NULL +#> ..$ inherit.blank: logi TRUE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ axis.ticks : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ axis.ticks.length : 'unit' num 2.75pt +#> ..- attr(*, "valid.unit")= int 8 +#> ..- attr(*, "unit")= chr "pt" +#> $ axis.line : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ axis.line.x : NULL +#> $ axis.line.y : NULL +#> $ legend.background :List of 5 +#> ..$ fill : chr "#FFFFFF00" +#> ..$ colour : logi NA +#> ..$ size : NULL +#> ..$ linetype : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_rect" "element" +#> $ legend.margin : 'margin' num [1:4] 5.5pt 5.5pt 5.5pt 5.5pt +#> ..- attr(*, "valid.unit")= int 8 +#> ..- attr(*, "unit")= chr "pt" +#> $ legend.spacing : 'unit' num 11pt +#> ..- attr(*, "valid.unit")= int 8 +#> ..- attr(*, "unit")= chr "pt" +#> $ legend.spacing.x : NULL +#> $ legend.spacing.y : NULL +#> $ legend.key : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.key.size : 'unit' num 1.2lines +#> ..- attr(*, "valid.unit")= int 3 +#> ..- attr(*, "unit")= chr "lines" +#> $ legend.key.height : NULL +#> $ legend.key.width : NULL +#> $ legend.text :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : chr "#4e4d47" +#> ..$ size : num 7 +#> ..$ hjust : num 0 +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ legend.text.align : num 0 +#> $ legend.title :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : num 8 +#> ..$ hjust : num 0 +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ legend.title.align : NULL +#> $ legend.position : chr "bottom" +#> $ legend.direction : NULL +#> $ legend.justification : chr "center" +#> $ legend.box : chr "horizontal" +#> $ legend.box.margin : 'margin' num [1:4] 0cm 0cm 0cm 0cm +#> ..- attr(*, "valid.unit")= int 1 +#> ..- attr(*, "unit")= chr "cm" +#> $ legend.box.background: list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.box.spacing : 'unit' num 11pt +#> ..- attr(*, "valid.unit")= int 8 +#> ..- attr(*, "unit")= chr "pt" +#> $ panel.background : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ panel.border : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ panel.spacing : 'unit' num [1:4] -0.1cm 0.7cm 0.2cm 1.7cm +#> ..- attr(*, "valid.unit")= int 1 +#> ..- attr(*, "unit")= chr "cm" +#> $ panel.spacing.x : NULL +#> $ panel.spacing.y : NULL +#> $ panel.grid :List of 6 +#> ..$ colour : chr "grey92" +#> ..$ size : NULL +#> ..$ linetype : NULL +#> ..$ lineend : NULL +#> ..$ arrow : logi FALSE +#> ..$ inherit.blank: logi TRUE +#> ..- attr(*, "class")= chr [1:2] "element_line" "element" +#> $ panel.grid.minor : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ panel.ontop : logi FALSE +#> $ plot.background : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ plot.title :List of 11 +#> ..$ family : NULL +#> ..$ face : chr "bold" +#> ..$ colour : chr "#4e4d47" +#> ..$ size : num 12 +#> ..$ hjust : num 0 +#> ..$ vjust : num 1 +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] 0pt 0pt 5.5pt 0pt +#> .. ..- attr(*, "valid.unit")= int 8 +#> .. ..- attr(*, "unit")= chr "pt" +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ plot.subtitle :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : chr "#4e4d47" +#> ..$ size : num 8 +#> ..$ hjust : num 0 +#> ..$ vjust : num 1 +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] -0.1cm 0cm -0.1cm 2cm +#> .. ..- attr(*, "valid.unit")= int 1 +#> .. ..- attr(*, "unit")= chr "cm" +#> ..$ debug : logi FALSE +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ plot.caption :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : chr "#939184" +#> ..$ size : num 6 +#> ..$ hjust : num 0.92 +#> ..$ vjust : num 1 +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] 0.2cm 0cm 0cm 0cm +#> .. ..- attr(*, "valid.unit")= int 1 +#> .. ..- attr(*, "unit")= chr "cm" +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ plot.tag :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : 'rel' num 1.2 +#> ..$ hjust : num 0.5 +#> ..$ vjust : num 0.5 +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi TRUE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ plot.tag.position : chr "topleft" +#> $ plot.margin : 'unit' num [1:4] 0.5cm 0.5cm 0.2cm 0.5cm +#> ..- attr(*, "valid.unit")= int 1 +#> ..- attr(*, "unit")= chr "cm" +#> $ strip.background : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ strip.placement : chr "inside" +#> $ strip.text :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : chr "grey10" +#> ..$ size : 'rel' num 0.8 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] 4.4pt 4.4pt 4.4pt 4.4pt +#> .. ..- attr(*, "valid.unit")= int 8 +#> .. ..- attr(*, "unit")= chr "pt" +#> ..$ debug : NULL +#> ..$ inherit.blank: logi TRUE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ strip.text.x : NULL +#> $ strip.text.y :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : NULL +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : num -90 +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi TRUE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ strip.switch.pad.grid: 'unit' num 2.75pt +#> ..- attr(*, "valid.unit")= int 8 +#> ..- attr(*, "unit")= chr "pt" +#> $ strip.switch.pad.wrap: 'unit' num 2.75pt +#> ..- attr(*, "valid.unit")= int 8 +#> ..- attr(*, "unit")= chr "pt" +#> $ panel.grid.major :List of 6 +#> ..$ colour : chr "#ebebe5" +#> ..$ size : num 0.2 +#> ..$ linetype : NULL +#> ..$ lineend : NULL +#> ..$ arrow : logi FALSE +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_line" "element" +#> - attr(*, "class")= chr [1:2] "theme" "gg" +#> - attr(*, "complete")= logi TRUE +#> - attr(*, "validate")= logi TRUE
    +
    +
    + +
    + +
    + + +
    +

    Site built with pkgdown 1.3.0.

    +
    +
    +
    + + + + + + diff --git a/docs/reference/kobo_unhcr_style_scatter.html b/docs/reference/kobo_unhcr_style_scatter.html new file mode 100644 index 0000000..2982739 --- /dev/null +++ b/docs/reference/kobo_unhcr_style_scatter.html @@ -0,0 +1,299 @@ + + + + + + + + +UNHCR ggplot2 theme — kobo_unhcr_style_scatter • koboloadeR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + +
    + +

    Return ggplot2 styling for scatter plot

    + +
    + +
    kobo_unhcr_style_scatter()
    + +

    Value

    + +

    Return UNHCR Style

    + + +

    Examples

    +
    kobo_unhcr_style_scatter()
    #> List of 20 +#> $ axis.title : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ axis.text :List of 11 +#> ..$ family : chr "Lato" +#> ..$ face : NULL +#> ..$ colour : chr "#222222" +#> ..$ size : num 11 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ axis.text.x :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : NULL +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] 5pt 0pt 9pt 0pt +#> .. ..- attr(*, "valid.unit")= int 8 +#> .. ..- attr(*, "unit")= chr "pt" +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ axis.ticks : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ axis.line : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.background : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.key : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.text :List of 11 +#> ..$ family : chr "Lato" +#> ..$ face : NULL +#> ..$ colour : chr "#222222" +#> ..$ size : num 9 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ legend.text.align : num 0 +#> $ legend.title : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ legend.position : chr "top" +#> $ panel.background : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ panel.grid.minor : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ panel.grid.major.x:List of 6 +#> ..$ colour : chr "#cbcbcb" +#> ..$ size : NULL +#> ..$ linetype : NULL +#> ..$ lineend : NULL +#> ..$ arrow : logi FALSE +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_line" "element" +#> $ panel.grid.major.y:List of 6 +#> ..$ colour : chr "#cbcbcb" +#> ..$ size : NULL +#> ..$ linetype : NULL +#> ..$ lineend : NULL +#> ..$ arrow : logi FALSE +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_line" "element" +#> $ plot.title :List of 11 +#> ..$ family : chr "Lato" +#> ..$ face : chr "bold" +#> ..$ colour : chr "#222222" +#> ..$ size : num 12 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ plot.subtitle :List of 11 +#> ..$ family : chr "Lato" +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : num 11 +#> ..$ hjust : NULL +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : 'margin' num [1:4] 9pt 0pt 9pt 0pt +#> .. ..- attr(*, "valid.unit")= int 8 +#> .. ..- attr(*, "unit")= chr "pt" +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> $ plot.caption : list() +#> ..- attr(*, "class")= chr [1:2] "element_blank" "element" +#> $ strip.background :List of 5 +#> ..$ fill : chr "white" +#> ..$ colour : NULL +#> ..$ size : NULL +#> ..$ linetype : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_rect" "element" +#> $ strip.text :List of 11 +#> ..$ family : NULL +#> ..$ face : NULL +#> ..$ colour : NULL +#> ..$ size : num 11 +#> ..$ hjust : num 0 +#> ..$ vjust : NULL +#> ..$ angle : NULL +#> ..$ lineheight : NULL +#> ..$ margin : NULL +#> ..$ debug : NULL +#> ..$ inherit.blank: logi FALSE +#> ..- attr(*, "class")= chr [1:2] "element_text" "element" +#> - attr(*, "class")= chr [1:2] "theme" "gg" +#> - attr(*, "complete")= logi FALSE +#> - attr(*, "validate")= logi TRUE
    +
    +
    + +
    + +
    + + +
    +

    Site built with pkgdown 1.3.0.

    +
    +
    +
    + + + + + + diff --git a/docs/reference/kobo_weight.html b/docs/reference/kobo_weight.html index 386b31d..3b550e0 100644 --- a/docs/reference/kobo_weight.html +++ b/docs/reference/kobo_weight.html @@ -6,7 +6,7 @@ -Weight the data — kobo_weight • koboloadeR +Weight a datset — kobo_weight • koboloadeR @@ -30,7 +30,7 @@ - + @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • @@ -114,7 +117,7 @@
    diff --git a/docs/reference/ltbl.html b/docs/reference/ltbl.html index 98a15ce..0535bc6 100644 --- a/docs/reference/ltbl.html +++ b/docs/reference/ltbl.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/multresponse.html b/docs/reference/multresponse.html index f44a855..bd3f804 100644 --- a/docs/reference/multresponse.html +++ b/docs/reference/multresponse.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/psum.html b/docs/reference/psum.html index 1472b22..7927120 100644 --- a/docs/reference/psum.html +++ b/docs/reference/psum.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/pwd_parse.html b/docs/reference/pwd_parse.html index 68a5a91..9dbeef9 100644 --- a/docs/reference/pwd_parse.html +++ b/docs/reference/pwd_parse.html @@ -90,6 +90,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/docs/reference/round2.html b/docs/reference/round2.html index 8024aba..29b9f5c 100644 --- a/docs/reference/round2.html +++ b/docs/reference/round2.html @@ -88,6 +88,9 @@
  • KoboloadeR Introduction
  • +
  • + Vignette Title +
  • diff --git a/inst/script/KoboloadeR User Journey Flow.png b/inst/script/KoboloadeR User Journey Flow.png new file mode 100644 index 0000000..df90795 Binary files /dev/null and b/inst/script/KoboloadeR User Journey Flow.png differ diff --git a/inst/script/form.xls b/inst/script/form.xls index 8d1f63c..c7c3636 100644 Binary files a/inst/script/form.xls and b/inst/script/form.xls differ diff --git a/inst/script/run-analysis.R b/inst/script/run-analysis.R index 7312fcd..67a231e 100644 --- a/inst/script/run-analysis.R +++ b/inst/script/run-analysis.R @@ -1,45 +1,25 @@ -#' @title Step by Step run Analysis -#' -#' @author Maher Daoud, Edouard legoupil -#' -#' -#' +######################## +### Console Script ##### +######################## library(koboloadeR) #### Phase 1: Project Configurationn ############# -################## Step1: Analysis project initiation ############# -result <- kobo_projectinit() ## Create analysis project structure -if (class(result) == "try-error") { - print(result) - return(FALSE) -} - -mainDir <- kobo_getMainDirectory() ## return current working directory - -################# Step2: Check if the file is exist ############# -form <- "form.xls" ## The name of the xlsform that exist under data folder -if (!file.exists(paste0(mainDir, "/data/",form))) { - print("Please make sure that this file exists with the same name under the data folder") - return(FALSE) -} - -################## Step3: Extend xlsform with necessary column ############# -result <- kobo_prepare_form(form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} +## Configure name of the xlsform that exist under data folder +# - Change if required but better to keep the defautl one +form <- "form.xls" +## Extend xlsform with necessary column kobo_prepare_form(form) -#### Eventually Generate dummy data -## kobo_dico(form) -## kobo_dummy(form) +### Eventually Generate dummy data (uncomment below if required) + # kobo_dummy(form) -### At this stage you can start working on your xlsform and fill it accordingly!!! +###################################################################################### +### At this stage you can start working on your xlsform and fill it accordingly!!! ### +###################################################################################### -################## Step4: Rename xlsform and Dataframes ################## +## Rename xlsform and Dataframes ## Please make sure in the settings sheet that you mentioned the main data frame and all sub dataframes ## The name field must be filled with the same name of begin-repeat name. ## The name of the Main Data Frame must be always "MainDataFrame", just to indicate that is the main one @@ -47,61 +27,34 @@ kobo_prepare_form(form) # name | label | value | path # 1 MainDataFrame | NA | mainDataFrame.csv | current-working-directory/data/mainDataFrame.csv # 2 br1 | NA | begin-repeat1.csv | current-working-directory/data/begin-repeat1.csv - -result <- kobo_rename_xlsform_dataframes(form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} kobo_rename_xlsform_dataframes(form) - - #### Phase 2: Analysis Plan ############################### - -result <- kobo_check_analysis_plan(form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} kobo_check_analysis_plan(form) - #### Phase 3: Load & process Data ############################### -result <- kobo_load_data(form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} kobo_load_data(form) -#### Phase 4: Generate Reports ############################### -################## Step1: Generate Crunching Report ############# -result <- kobo_crunching_report(form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} +#### Phase 4: Generate Analysis Reports ############################### + +## Generate Crunching Report --> Describe kobo_crunching_report(form) -################## Step2: Generate Cluster Report ############# +## Generate Cluster Report --> Discover household <- read.csv(paste(mainDir, "data", "/MainDataFrame.csv", sep = "/", collapse = "/"), stringsAsFactors = F) ## This dataset will be generated by kobo_load_data -result <- kobo_cluster_report(frame = household, form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} kobo_cluster_report(frame = household, form) -################## Step3: Generate Anonymisation Report ############# +## Generate Prediction Report --> Predict + +## Generate Scoring Report --> Prescribe + + +#### Phase 5: Statistical Disclosure control & Indicator sharing ############################### +## Generate Anonymisation Report household <- read.csv(paste(mainDir, "data", "/MainDataFrame.csv", sep = "/", collapse = "/"), stringsAsFactors = F) ## This dataset will be generated by kobo_load_data -result <- kobo_anonymisation_report(frame = household, form) -if (class(result) == "try-error") { - print(result) - return(FALSE) -} kobo_anonymisation_report(frame = household, form) + diff --git a/man/kobo_anonymise.Rd b/man/kobo_anonymise.Rd index 7cead4d..dae114c 100644 --- a/man/kobo_anonymise.Rd +++ b/man/kobo_anonymise.Rd @@ -40,8 +40,6 @@ The methods above can be reference in the column } } \examples{ -kobo_anonymise() - \dontrun{ kobo_anonymise(frame, dico) } diff --git a/man/kobo_get_theme.Rd b/man/kobo_get_theme.Rd index ae03f41..062145c 100644 --- a/man/kobo_get_theme.Rd +++ b/man/kobo_get_theme.Rd @@ -4,7 +4,7 @@ \alias{kobo_get_theme} \title{Get Themes} \usage{ -kobo_get_theme(form = "form.xls") +kobo_get_theme() } \value{ Return a list that contains all themes diff --git a/man/kobo_left_align.Rd b/man/kobo_left_align.Rd new file mode 100644 index 0000000..96b7930 --- /dev/null +++ b/man/kobo_left_align.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/kobo_left_align.R +\name{kobo_left_align} +\alias{kobo_left_align} +\title{UNHCR ggplot2 theme} +\usage{ +kobo_left_align(plot_name, pieces) +} +\value{ +Return better chart +} +\description{ +Left align chart title and subtitle on a ggplot2 +} +\examples{ +kobo_left_align() + +} +\author{ +Edouard Legoupil - with inspiration from bbc +} diff --git a/man/kobo_prediction_report.Rd b/man/kobo_prediction_report.Rd index 245a710..9cbf37e 100644 --- a/man/kobo_prediction_report.Rd +++ b/man/kobo_prediction_report.Rd @@ -3,9 +3,6 @@ \name{kobo_prediction_report} \alias{kobo_prediction_report} \title{Generate prediction} -\usage{ -kobo_prediction_report(dico, frame, registry) -} \arguments{ \item{kobo}{or odk dataset to use} } diff --git a/man/kobo_unhcr_style_bar.Rd b/man/kobo_unhcr_style_bar.Rd new file mode 100644 index 0000000..e98c93c --- /dev/null +++ b/man/kobo_unhcr_style_bar.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/kobo_unhcr_style_bar.R +\name{kobo_unhcr_style_bar} +\alias{kobo_unhcr_style_bar} +\title{UNHCR ggplot2 theme} +\usage{ +kobo_unhcr_style_bar() +} +\value{ +Return UNHCR Style +} +\description{ +Return ggplot2 styling for bar chart +} +\examples{ +kobo_unhcr_style_bar() + +} +\author{ +Edouard Legoupil - with inspiration from bbc +} diff --git a/man/kobo_unhcr_style_histo.Rd b/man/kobo_unhcr_style_histo.Rd new file mode 100644 index 0000000..d4f8422 --- /dev/null +++ b/man/kobo_unhcr_style_histo.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/kobo_unhcr_style_histo.R +\name{kobo_unhcr_style_histo} +\alias{kobo_unhcr_style_histo} +\title{UNHCR ggplot2 theme} +\usage{ +kobo_unhcr_style_histo() +} +\value{ +Return UNHCR Style +} +\description{ +Return ggplot2 styling for histogram +} +\examples{ +kobo_unhcr_style_histo() + +} +\author{ +Edouard Legoupil - with inspiration from bbc +} diff --git a/man/kobo_unhcr_style_map.Rd b/man/kobo_unhcr_style_map.Rd new file mode 100644 index 0000000..32e1050 --- /dev/null +++ b/man/kobo_unhcr_style_map.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/kobo_unhcr_style_map.R +\name{kobo_unhcr_style_map} +\alias{kobo_unhcr_style_map} +\title{UNHCR ggplot2 theme} +\usage{ +kobo_unhcr_style_map() +} +\value{ +Return UNHCR Style +} +\description{ +Return ggplot2 styling for maps +} +\examples{ +kobo_unhcr_style_map() + +} +\author{ +Edouard Legoupil - +} diff --git a/man/kobo_unhcr_style_scatter.Rd b/man/kobo_unhcr_style_scatter.Rd new file mode 100644 index 0000000..a558ac1 --- /dev/null +++ b/man/kobo_unhcr_style_scatter.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/kobo_unhcr_style_scatter.R +\name{kobo_unhcr_style_scatter} +\alias{kobo_unhcr_style_scatter} +\title{UNHCR ggplot2 theme} +\usage{ +kobo_unhcr_style_scatter() +} +\value{ +Return UNHCR Style +} +\description{ +Return ggplot2 styling for scatter plot +} +\examples{ +kobo_unhcr_style_scatter() + +} +\author{ +Edouard Legoupil - with inspiration from bbc +} diff --git a/tests/testthat/test-to_xlsform.R b/tests/testthat/test-to_xlsform.R deleted file mode 100644 index cc4c56f..0000000 --- a/tests/testthat/test-to_xlsform.R +++ /dev/null @@ -1,7 +0,0 @@ -context("kobo generate xlsform test") - - -test_that("generate xlsform test", { - expect_output(kobo_to_xlsform(mtcars), "XLS form has been successfully generated") - expect_output(kobo_to_xlsform(mtcars, n=15), "XLS form has been successfully generated") -}) \ No newline at end of file diff --git a/vignettes/tutorial.Rmd b/vignettes/tutorial.Rmd index ad0f267..bff4686 100644 --- a/vignettes/tutorial.Rmd +++ b/vignettes/tutorial.Rmd @@ -7,14 +7,14 @@ output: toc: yes toc_depth: 3 vignette: > - %\VignetteIndexEntry{KoboloadeR Examples} + %\VignetteIndexEntry{KoboloadeR Introduction} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r set-options, echo=FALSE, cache=FALSE} -options(width=120) +options(width = 120) #opts_chunk$set(comment = "", warning = FALSE, message = FALSE, echo = TRUE, tidy = FALSE, size="small") #read_chunk("some/script/I/want/to/load.R") ``` @@ -22,11 +22,11 @@ options(width=120) ## Introduction -Kooloader is designed to facilitate the analysis workflow of a survey collected through any xlsform compatible platform. +KoboloadeR is designed to facilitate the analysis workflow of a survey collected through any xlsform compatible platform. The package is designed to support 2 user flow: - * __Graphical User Interface - GUI__: A dedicated shynyapp `kobo_shiny("app_main_koboloadeR.R")` includes all instructions and options to run your project. + * __Graphical User Interface - GUI__: A dedicated shinyApp `kobo_shiny("app_main_koboloadeR.R")` includes all instructions and options to run your project. * __Console mode__ gives you way to run your analysis without GUI @@ -38,7 +38,7 @@ First you will need to install all the required software described in the packag You can now create a project, enable the library with -Loads koboloadeR package +Loads KoboloadeR package > library (koboloadeR) @@ -49,45 +49,44 @@ Creates folders necessary and transfer files needed. This function implement goo This will also push on your data folder a demo project with a form template that you can adapt according to your needs. Note that in the development of your form, in addition of this template, you can use the [Integrated Framework for Household survey knowledge base](https://unhcr.github.io/Integrated-framework-household-survey) -## Generate dummy data -**You can skip this step in case you already have your own questionnaire and dataset.** +## Extend your xlsform -In order to run this tutorial, we will first generate a dummy dataset using the structure of the form. +The very first step is to extend your exisitng xlsform to include new column for your project configuration and analysis plan. -This can be performed with +koboloader concept is that all the configuration shall exclusively be done in the orginial excel file. This is done for various reasons: -Define the path to your form file (note that we use `.xls` file only) + * No need to create any R scripts which allow user with minimum R knowldege to use the package + * Reproducibility * Documentation: this approach ensure that the analysis workflow is _de facto_ fully documented within that excel file + +Define the path to your form file (note that we use `.xls` file only) > form <- "form.xls" -Now use the function to generate your dummy file. - -> kobo_dummy_data(form) -This function will generate multiple csv files as the template form includes `begin_group` elements corresponding to a hierarchical data structure. A hierarchical structure is created when a series of questions is repeated say for each member in the household, and combined with a household questionnaire. +Now we will automatically add the required additional structure for the analysis plan and project configuration with that same file -All csv files will be saved per default in the `data` folder. +> kobo_prepare_form(form) +## Generate dummy data -## Extend your xlsform +**You can skip this step in case you already have your own questionnaire and dataset.** -The very first step is to extend your exisitng xlsform to include new column for your project configuration and analysis plan. +In order to run this tutorial, we will first generate a dummy dataset using the structure of the form. -koboloader concept is that all the configuration shall exclusively be done in the orginial excel file. This is done for various reasons: +This can be performed with - * No need to create any R scripts which allow user with minimum R knowldege to use the package - * Reproducibility * Documentation: this approach ensure that the analysis workflow is _de facto_ fully documented within that excel file - -Define the path to your form file (note that we use `.xls` file only) +Define the path to your form file (note that we use `.xls` file only) > form <- "form.xls" +Now use the function to generate your dummy file. -Now we will automatically add the required additional structure for the analysis plan and project configuration with that same file +> kobo_dummy_data(form) -> kobo_prepare_form(form) +This function will generate multiple csv files as the template form includes `begin_group` elements corresponding to a hierarchical data structure. A hierarchical structure is created when a series of questions is repeated say for each member in the household, and combined with a household questionnaire. +All csv files will be saved per default in the `data` folder. ## Set up your project configuration @@ -110,4 +109,4 @@ You have now set up all your project and you got your initial reports. Analysis is an **iterative** process. you will need to - `run-analysis.R` +> `run-analysis.R`