Package contains tools to support design and use of questionnaires programmed in XLSForm.
Download the library from Github:
devtools::install_github("williameoswald/surveydesignr")
Load libraries:
library("surveydesignr")
library("tidyverse")
library("janitor")
library("readxl")
library("flextable")
library("stringr")
Function for importing a XLSForm and creating a readable dataframe or flextable object that lists variable names, labels in up to two languages, relevancies, constraints, and calculate fields. Output objects can be easily exported to Microsoft Word using Officer, ultimately allowing for questionnaires to be directly programmed in XLSform and then easily shared and reviewed by collaborators or included in protocol or other text documents.
If XLSform includes multiple languages, you can choose the language to output by specifying the primary argument. For example, specifying "English" as the primary argument means function will use columns containing "label::English", "hint::English", etc., ignoring capitalisation. To output a second language side-by-side, specify the primary argument and a second language as the secondary argument. Please note that if your label column name includes spaces or other punctuation (e.g. "label::English (en)") the function will remove these and replace with underscores ("_"), so you will need to input "English_en".
Setting both primary and secondary to NULL will allow you to output a table for forms without any language specified, i.e. with columns "label","hint", etc.
xlsformfile <- "filepath to XLSForm here"
# Specify flex=TRUE (default) to output the table as a formatted flextable object.
quest_table <- export_quest(xlsformfile,primary="English",secondary=NULL)
# Specify flex=FALSE to output the table as a tibble.
quest_table <- export_quest(xlsformfile,primary="English",secondary=NULL,flex=FALSE)
library("officer")
library("flextable")
text_style <- fp_text(font.size = 12, font.family = "Calibri", bold = TRUE)
par_style <- fp_par(text.align = "justify")
read_docx() %>% body_remove() %>%
body_add_flextable(quest_table) %>%
print(target = paste0("questionnaire.docx"))
Function for comparing two XLSForm Docs. Currently designed for use with SurveyCTO XLSForm files but should be usable or modifiable for use with ODK forms.
Please ensure the "label", "hint", "constraint message" columns are named "label:English", "hint:English", and "constraint message:English". Additional language columns (only one additional language at a time for now) can be examined by specifying them as a third argument according to how the language is named in the form (e.g. "Francais" for label:Francais).
form1location <- "filepath to first XLSForm here"
form2location <- "filepath to second XLSForm here"
# Name output of function "full_compare""
full_compare <- compare_survey(form1location,form2location,language)
# Flextable of content comparison
tabulate_comparison(full_compare,1)
- Compare content - list items not present in both survey sheets
- Get row number for each item in form 1 relative to same item's position in form 2
- Compare type per name
- Compare calculation fields for calculate items
- Compare all constraint fields
- Compare all relevance fields
- Compare English labels
- Compare English constraint messages
- Compare English hints
- Compare Other language labels
- Compare Other language constraint messages
- Compare Other language constraint messages
tabulate_comparison(1)
tabulate_comparison(2)
tabulate_comparison(3)
tabulate_comparison(4)
tabulate_comparison(5)
tabulate_comparison(6)
tabulate_comparison(7)
tabulate_comparison(8)
tabulate_comparison(9)
tabulate_comparison(10)
tabulate_comparison(11)
tabulate_comparison(12)
- Add display of question type (select_one, select_multiple) and constraint message to table
- Revise comparison function to allow for forms without language specification
- Add comparison of choices tab
- Make cleaner output
- Functionalise repeated actions
Please contact me with any questions or suggestions.
Available for use under a CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode).