-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathkobo_likert.R
69 lines (54 loc) · 2.52 KB
/
kobo_likert.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# WARNING - Generated by {fusen} from dev/flat_dev.Rmd: do not edit by hand
#' @title Crunch all likert variables according to the analysis plan
#'
#' @param datalist An object of the "datalist" class as defined in kobocruncher
#' @param dico path to the xlsform file used to colllect the data
#' @param datasource name of the data source to display, if set to NULL - then pulls the form_title within the settings of the xlsform
#' @export
#' @examples
#' dicolikert <- kobo_dico( xlsformpath = system.file("form_likert.xlsx", package = "kobocruncher") )
#' datalistlikert <- kobo_data(datapath = system.file("data_likert.xlsx", package = "kobocruncher") )
#'
#' kobo_likert(datalist = datalistlikert,
#' dico = dicolikert,
#' datasource = "a great survey!")
#'
#'
# prefixer::import_from(fun = kobo_likert)
kobo_likert <- function(datalist = datalist,
datasource = NULL,
dico = dico) {
## Get default data source name
if( is.null(datasource)) {datasource <- as.character( dico[[3]]$form_title ) }
#require(dplyr)
## Check the frequency of list_name within each group,
## Filter the combination of list and group where we have more than 3 occurrences
# not taking in account when the appearance is not "label"
grouplikert <- as.data.frame(dico[["variables"]]) |>
dplyr::filter( type == "select_one") |>
dplyr::filter( appearance != "label") |>
## Just include the var that are also in the plan
dplyr::filter(name %in% dico[["plan"]]$name ) |>
dplyr::group_by( scope, list_name, repeatvar) |>
dplyr::summarise( cnt= dplyr::n() )|>
dplyr::filter( cnt >= 2)
if(nrow(grouplikert) == 0) {
cat("No potential likert in the form")
} else {
cat(paste0(nrow(grouplikert), " groups of likert questions in the form"))
for (i in 1:nrow(grouplikert) ) {
## getting the group and corresponding label
scopei <- as.character(grouplikert[i, c("scope")])
repeatvari <- as.character(grouplikert[i, c("repeatvar")])
## geting the list_name and corresponding label
list_namei <- as.character( grouplikert[i, c("list_name")])
print(plot_likert(datalist = datalist,
datasource = datasource,
dico = dico,
scopei = scopei,
repeatvari = repeatvari,
list_namei = list_namei,
showcode = TRUE))
}
}
}