Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
Merge branch '10-as-dev-i-would-like-to-have-a-questionnaire-class' of https://github.com/unhcr-americas/surveyDesigner into 10-as-dev-i-would-like-to-have-a-questionnaire-class

# Conflicts:
#	.Rbuildignore
  • Loading branch information
Edouard-Legoupil committed Apr 25, 2023
2 parents 1b70b2d + 5d46f08 commit 43d912b
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 119 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ $run_dev.*
^\.github$
^surveyDesigner\.Rproj$
^docs$
<<<<<<< HEAD
^app\.R$
=======
>>>>>>> 5d46f08550c1eb5c6e5e288d470fff79faa8a585
^rsconnect$
1 change: 1 addition & 0 deletions R/get_groups.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ get_choices_for_question <- function(survey, full_name){
#'
#' @noRd


contains_groups <- function(data){
any(grepl(x = data[["type"]], pattern = 'begin_group|begin_repeat|end_group|end_repeat'))
}
Expand Down
2 changes: 1 addition & 1 deletion R/globals.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
globalVariables(unique(c(
# get_choices_for_question:
"list_name", "name",
"list_name", "name", "label",
# get_groups:
".",
# get_groups : <anonymous>:
Expand Down
3 changes: 2 additions & 1 deletion R/referential.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ Referential <- R6::R6Class(classname = "Referential",
# TODO checking survey and other sheets

# survey have to be a xlsform

if(!contains_groups(data$survey)){
stop("the sheet 'survey' doesn't includes groups")
stop("the sheet 'survey' doesn't includes groups - i.e. questions organised as module")
}

self$data <- data
Expand Down
82 changes: 43 additions & 39 deletions dev/flat_r6_referential.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ Referential <- R6::R6Class(classname = "Referential",
# TODO checking survey and other sheets
# survey have to be a xlsform
if(!contains_groups(data$survey)){
stop("the sheet 'survey' doesn't includes groups")
stop("the sheet 'survey' doesn't includes groups - i.e. questions organised as module")
}
self$data <- data
Expand Down Expand Up @@ -128,42 +129,6 @@ test_that("r6_referential works", {

# Utils for referential manipulation

```{r development-utils, eval = FALSE}
data <- ref$data$survey
begin_start <- grep(x = , "begin_")
end_stop <- grep(x = data[["type"]], "end_")
if(length(begin_start) != length(end_stop)){
stop("Miss one begin or stop in the data")
}
if(!all(begin_start < end_stop)){
stop("One begin is before a end")
}
by_begin_end <- purrr::map2(begin_start, end_stop,
function(x,y){
data_to_get <- data %>%
slice(x:y)
by_groups <- list(data = data_to_get %>%
filter(!type %in% c("begin_group", "end_group")),
information = data_to_get %>%
filter(type %in% c("begin_group", "end_group"))
)
# names(by_groups) <- by_groups[["information"]][["name"]]
by_groups
}) %>%
purrr::set_names(nm = purrr::map(., ~ .x[["information"]][["name"]][1]))
```


```{r function-utils_xlsform}
survey_designer <- new.env()
Expand Down Expand Up @@ -246,6 +211,7 @@ get_choices_for_question <- function(survey, full_name){
#'
#' @noRd
contains_groups <- function(data){
any(grepl(x = data[["type"]], pattern = 'begin_group|begin_repeat|end_group|end_repeat'))
}
Expand All @@ -264,6 +230,44 @@ names_of_sheet <- function(path){
}
}
```


```{r development-utils, eval = FALSE}
data <- ref$data$survey
begin_start <- grep(x = , "begin_")
end_stop <- grep(x = data[["type"]], "end_")
if(length(begin_start) != length(end_stop)){
stop("Miss one begin or stop in the data")
}
if(!all(begin_start < end_stop)){
stop("One begin is before a end")
}
by_begin_end <- purrr::map2(begin_start, end_stop,
function(x,y){
data_to_get <- data %>%
slice(x:y)
by_groups <- list(data = data_to_get %>%
filter(!type %in% c("begin_group", "end_group")),
information = data_to_get %>%
filter(type %in% c("begin_group", "end_group"))
)
# names(by_groups) <- by_groups[["information"]][["name"]]
by_groups
}) %>%
purrr::set_names(nm = purrr::map(., ~ .x[["information"]][["name"]][1]))
```



```{r tests-utils_xlsform}
Expand All @@ -281,9 +285,9 @@ expect_type(result, "list")
expect_true(inherits(get_choices_for_question, "function"))
get_chocies <- get_choices_for_question(ref$data$choices, "pop_groups", "English")
get_choices <- get_choices_for_question(ref$data$choices, "pop_groups")
expect_type(get_chocies, "list")
expect_type(get_choices, "list")
})
```
Expand Down
Binary file modified inst/SurveyDesigner_Referential.xlsx
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/testthat/test-get_groups.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ expect_type(result, "list")


expect_true(inherits(get_choices_for_question, "function"))
get_chocies <- get_choices_for_question(ref$data$choices, "pop_groups", "English")
get_choices <- get_choices_for_question(ref$data$choices, "pop_groups")

expect_type(get_chocies, "list")
expect_type(get_choices, "list")

})
48 changes: 0 additions & 48 deletions vignettes/class-r6-for-the-referencial.Rmd

This file was deleted.

4 changes: 4 additions & 0 deletions vignettes/class-r6-for-the-referential.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ ref$by_groups$group_intro










Expand Down
28 changes: 0 additions & 28 deletions vignettes/mon-module-home.Rmd

This file was deleted.

0 comments on commit 43d912b

Please sign in to comment.