Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #66 from unhcr/gh-pages
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
Edouard-Legoupil authored Nov 14, 2020
2 parents 20e3216 b185865 commit 18872d5
Show file tree
Hide file tree
Showing 158 changed files with 3,852 additions and 1,605 deletions.
16 changes: 13 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
Type: Package
Package: koboloadeR
Title: A Metapackage for Survey Data Crunching
Version: 0.1.7
Version: 0.1.8
Authors@R:
c(person(given = "Edouard",
family = "Legoupil",
Expand All @@ -11,6 11,10 @@ Authors@R:
family = "Daoud",
role = "aut",
email = "[email protected]"),
person(given = "Hisham",
family = "Galal",
role = "aut",
email = "[email protected]"),
person(given = "Elliott",
family = "Messeiller",
role = "ctb",
Expand Down Expand Up @@ -58,6 62,7 @@ Imports:
pander,
pls,
plyr,
qpdf,
randomForest,
rattle,
RColorBrewer,
Expand All @@ -82,14 87,19 @@ Imports:
stringi,
stringr,
survey,
tidyverse,
tools,
truncnorm,
tidyverse,
VIM,
viridis,
xgboost,
xlsx
jsonlite,
magrittr,
tibble,
miniUI,
ckanr,
openxlsx,
fs
Suggests:
testthat (>= 2.1.0)
VignetteBuilder:
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 22,7 @@ export(kobo_ddi)
export(kobo_dico)
export(kobo_dummy)
export(kobo_edit_form)
export(kobo_edit_ridl_metadata)
export(kobo_encode)
export(kobo_encode_repeat)
export(kobo_form)
Expand Down Expand Up @@ -49,6 50,9 @@ export(kobo_samplingframe)
export(kobo_shiny)
export(kobo_split_multiple)
export(kobo_submission_count)
export(kobo_submit_ridl_package)
export(kobo_submit_ridl_resource)
export(kobo_submit_to_ridl)
export(kobo_time_parser_UTC)
export(kobo_to_xlsform)
export(kobo_unhcr_style_bar)
Expand All @@ -68,3 72,4 @@ import(RCurl)
import(httr)
import(plyr)
import(readxl)
importFrom(magrittr,"%>%")
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 1,12 @@
## koboloadeR 0.1.8

* Refactored the koboloadeR project structure so that it looks like a data package - R, data-raw, data - applying suggestions made here: https://raw.githubusercontent.com/statnmap/prez/master/2019-07_useR_Toulouse.pdf

* Included dependency to unhcRstyle package where all the brand style is managed - used now an argument to crunching report function

* Saving now all intermediary file as binary rda -- not yet tested fully...


## koboloadeR 0.1.7

* Added different output for the crunching report - docx, pptx, html, aspx
Expand Down
2 changes: 1 addition & 1 deletion R/kobo_aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,7 @@
#' }
#'

kobo_aggregate <- function( form = "form.xls",
kobo_aggregate <- function( form = "form.xlsx",
aggregVar = "admin1") {

# aggregVar = mapref
Expand Down
4 changes: 2 additions & 2 deletions R/kobo_anonymisation_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 16,14 @@
#'
#' @examples
#' \dontrun{
#' kobo_anonymisation_report(frame, form = "form.xls")
#' kobo_anonymisation_report(frame, form = "form.xlsx")
#' }
#'
#' @export kobo_anonymisation_report
#'
#'

kobo_anonymisation_report <- function(frame, form = "form.xls", app = "console") {
kobo_anonymisation_report <- function(frame, form = "form.xlsx", app = "console") {
tryCatch({
if (app == "shiny") {
progress <- shiny::Progress$new()
Expand Down
4 changes: 2 additions & 2 deletions R/kobo_anonymise.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 41,11 @@
#'
#' @examples
#' \dontrun{
#' kobo_anonymise(frame, form = "form.xls")
#' kobo_anonymise(frame, form = "form.xlsx")
#' }
#'

kobo_anonymise <- function(frame, form = "form.xls", app = "console") {
kobo_anonymise <- function(frame, form = "form.xlsx", app = "console") {

mainDir <- kobo_getMainDirectory()
form_tmp <- paste(mainDir, "data", form, sep = "/", collapse = "/")
Expand Down
2 changes: 1 addition & 1 deletion R/kobo_atlas_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 24,7 @@
#' }
#'

kobo_atlas_report <- function(form = "form.xls",
kobo_atlas_report <- function(form = "form.xlsx",
app = "console",
output ="html",
render = "TRUE",
Expand Down
4 changes: 2 additions & 2 deletions R/kobo_check_analysis_plan.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 14,13 @@
#'
#' @examples
#' \dontrun{
#' kobo_check_analysis_plan("myform.xls")
#' kobo_check_analysis_plan("form.xlsx")
#' }
#'
#' @export kobo_check_analysis_plan
#'

kobo_check_analysis_plan <- function(form = "form.xls") {
kobo_check_analysis_plan <- function(form = "form.xlsx") {
tryCatch({
result <- list()
result$flag <- T
Expand Down
4 changes: 2 additions & 2 deletions R/kobo_check_project_configuration.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 14,13 @@
#'
#' @examples
#' \dontrun{
#' kobo_check_project_configuration("myform.xls")
#' kobo_check_project_configuration("myform.xlsx")
#' }
#'
#' @export kobo_check_project_configuration
#'

kobo_check_project_configuration <- function(form = "form.xls") {
kobo_check_project_configuration <- function(form = "form.xlsx") {
tryCatch({
result <- list()
result$flag <- T
Expand Down
42 changes: 24 additions & 18 deletions R/kobo_clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 20,24 @@
#'
#' @examples
#' \dontrun{
#' kobo_clean(frame, form = "form.xls")
#' kobo_clean(frame, form = "form.xlsx")
#' }
#'
#'

kobo_clean <- function(frame, form = "form.xls", app = "console") {
kobo_clean <- function(frame, form = "form.xlsx", app = "console") {

mainDir <- kobo_getMainDirectory()
form <- as.character(form)
#cat(paste0(form,"\n"))
formpath <- as.character(paste0(mainDir,"/data/dico_",form,".csv"))
#cat(paste0(formpath,"\n"))
dico <- utils::read.csv(formpath, encoding = "UTF-8", na.strings = "")


#formpath <- as.character(paste0(mainDir,"/data/dico_",form,".rda"))
#cat(paste0(formpath,"\n"))
#load(formpath)

# frame <- MainDataFrame
# frame <- household
Expand All @@ -49,7 54,8 @@ kobo_clean <- function(frame, form = "form.xls", app = "console") {
dico.clean <- dico[ !(is.na(dico[, c("clean")])) , ]
if (nrow(dico.clean) > 0) {
cat(paste0(nrow(dico.clean), " potential variables to clean\n"))


if (file.exists("R/apply_clean.R")) file.remove("R/apply_clean.R")
for (i in 1:nrow(dico.clean)) {
# i <- 1
cat(paste0(i, "- Clean through an external table, if exists, the value of question: ", as.character(dico.clean[ i, c("label")]),"\n"))
Expand All @@ -58,7 64,7 @@ kobo_clean <- function(frame, form = "form.xls", app = "console") {
variable <- paste0(as.character(dico.clean[ i, c("fullname")]))
cleanfile <- paste0(as.character(dico.clean[ i, c("clean")]))
cleanframe <- paste0(substr(as.character(dico.clean[ i, c("clean")]), 1, nchar(cleanfile) - 4))
formula1 <- paste0(cleanframe," <- utils::read.csv(\"data/", cleanfile,"\", encoding = \"UTF-8\", na.strings = \"\")" )
formula1 <- paste0(cleanframe," <- utils::read.csv(\"data-raw/", cleanfile,"\", encoding = \"UTF-8\", na.strings = \"\")" )
formula2 <- paste0("names(",cleanframe,")[1] <- \"",dico.clean[ i, c("fullname")],"\"" )
formula3 <- paste0("names(",cleanframe,")[2] <- \"",dico.clean[ i, c("fullname")],".clean\"" )
formula4 <- paste0("colname <- which(colnames(",framename,") == \"", variable,"\")")
Expand All @@ -69,20 75,20 @@ kobo_clean <- function(frame, form = "form.xls", app = "console") {
formula9 <- paste0("round( nrow(", framename ,"[ !(is.na(", framename ,"$", variable ,".clean)), ]) / nrow(", framename ,") *100,digits = 1),\"%\n\n\"))")


if (file.exists("code/temp-clean.R")) file.remove("code/temp-clean.R")
cat(paste0("if (\"", as.character(dico.clean[ i, c("fullname")]) , "\" %in% names(", framename, ")) {" ), file = "code/temp-clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula1, ""), file = "code/temp-clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula2, ""), file = "code/temp-clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula3, ""), file = "code/temp-clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula4, ""), file = "code/temp-clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula5, ""), file = "code/temp-clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula6, ""), file = "code/temp-clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula7, ""), file = "code/temp-clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula8, ""), file = "code/temp-clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula9, "} else {cat(\" That variable is not in that frame...\n\") } "), file = "code/temp-clean.R" , sep = "\n", append = TRUE)
source("code/temp-clean.R")
if (file.exists("code/temp-clean.R")) file.remove("code/temp-clean.R")
}
cat(paste0("if (\"", as.character(dico.clean[ i, c("fullname")]) , "\" %in% names(", framename, ")) {" ), file = "R/apply_clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula1, ""), file = "R/apply_clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula2, ""), file = "R/apply_clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula3, ""), file = "R/apply_clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula4, ""), file = "R/apply_clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula5, ""), file = "R/apply_clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula6, ""), file = "R/apply_clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula7, ""), file = "R/apply_clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula8, ""), file = "R/apply_clean.R" , sep = "\n", append = TRUE)
cat(paste0(formula9, "} else {cat(\" That variable is not in that frame...\n\") } "), file = "R/apply_clean.R" , sep = "\n", append = TRUE)

}
source("R/apply_clean.R")
#if (file.exists("R/apply_clean.R")) file.remove("R/apply_clean.R")
}
}
return(frame)
Expand Down
4 changes: 2 additions & 2 deletions R/kobo_cluster_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 19,12 @@
#'
#' @examples
#' \dontrun{
#' kobo_cluster_report(frame = MainDataFrame , form = "form.xls")
#' kobo_cluster_report(frame = MainDataFrame , form = "form.xlsx")
#' }
#'

kobo_cluster_report <- function(frame = MainDataFrame ,
form = "form.xls",
form = "form.xlsx",
output ="html",
app = "console") {
tryCatch({
Expand Down
4 changes: 2 additions & 2 deletions R/kobo_consolidateone.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 14,13 @@
#'
#' @examples
#' \dontrun{
#' kobo_consolidateone(frame , form = "form.xls")
#' kobo_consolidateone(frame , form = "form.xlsx")
#' }
#'
#'
#' @return data

kobo_consolidateone <- function(frame , form = "form.xls") {
kobo_consolidateone <- function(frame , form = "form.xlsx") {

configInfo <- kobo_get_config()
mainDir <- kobo_getMainDirectory()
Expand Down
2 changes: 1 addition & 1 deletion R/kobo_correlation_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 22,7 @@
#' @export kobo_correlation_analysis
#'

kobo_correlation_analysis <- function(form = "form.xls", frame, target, app = "console") {
kobo_correlation_analysis <- function(form = "form.xlsx", frame, target, app = "console") {
tryCatch({
if (nrow(frame) == 0) {
return(structure("Error: the frame is empty", class = "try-error"))
Expand Down
Loading

0 comments on commit 18872d5

Please sign in to comment.