Source Code Layout - tufts-oir/QualtricsTools GitHub Wiki
Top Level Files
These are the source code files which are contained in the R/ folder. Each of the files and its contents are described below.
comment_coding.Rdata.Rhelper_functions.Rhtml_results.Rloading_results.Rpandoc_conversion.Rquestion_type_checking.Rreorganizing_survey_data.Rresults_generation.R
comment_coding.R
The functions contained in comment_coding.R are written for users to import CSV and XLSX sheets which categorize the raw text comments of a survey and include them as "Coded Comments" tables in the Text Appendices portion of the generated report.
directory_get_coded_comment_sheetsget_coded_comment_sheetget_coded_comment_sheet_fmpget_coded_comment_sheet_NVivoformat_coded_comments_fmpformat_coded_comments_NVivoformat_coded_comment_sheetsmerge_split_column_into_comment_sheetformat_and_split_comment_sheetsinsert_coded_commentsinsert_split_survey_comments
data.R
This file does not contain any functions, but rather provides the names of the data files which should be imported from the data/ folder. This includes some sample data for testing.
helper_functions.R
The helper functions contained in this file are functions which are relied
upon by many functions found in different parts of the application. The
functions app and get_setup are two functions which users will regularly
encounter. Functions such as question_from_response_column, find_question,
find_question_index, find_question_index_by_qid, and others are functions
which lookup values or indices corresponding to their inputs and are relied
upon in the application to find where data should be sourced from or inserted into.
repathquestion_from_response_columnchoice_text_from_questionappget_setupfind_questionfind_question_indexfind_question_index_by_qidchoice_text_from_response_columnblocks_header_to_htmlnumber_of_blocksquestions_from_blocksflow_from_surveyget_setup_in_environmentmake_results_tablesmake_text_appendicesmake_coded_commentsmake_split_results_tablesmake_split_text_appendicesmake_split_coded_comments
html_results.R
The QualtricsTools application builds reports in HTML before rendering them
into other formats with Pandoc. The functions contained in this file are those
which help in rendering the HTML reports seen in the Shiny app. create_html_results_tables, text_appendices_table, and tabelize_display_logic are the most critical
functions in this file, and they produce the Results Tables, Text Appendices, and Survey Logic reports.
create_html_results_tablesquestion_descriptionhas_display_logictext_appendices_tableuncodeable_questions_messagetabelize_display_logicappendix_letteringtable_html_coded_commentstable_no_respondentstable_text_entrytable_non_text_entrytable_mcsa_multitext
loading_results.R
These are functions which are used to import Qualtrics survey data in a standardized way, as well as to provide a graphical interface to choose the data to be loaded. validate_data_export_tags ensures that the Qualtrics Survey File uploaded does not have any duplicate data export tags.
load_csv_dataload_qsf_dataask_for_qsfask_for_csvvalidate_data_export_tags
pandoc_conversion.R
The data which is produced in html_results.R is passed to this single
function, with parameters including the desired output extension and
desired output file name. html_2_pandoc then uses system calls to Pandoc
to convert the file (in temporary memory) and then moves it to the desired
output location.
html_2_pandoc
question_type_checking.R
An integral part of the results generation is the tabling of frequencies of responses and choices to a given question. Depending on the question's format, these frequencies need to be tabled differently. In order to reliably detect what format a given question is, the following functions are used, which each return boolean values indicating the type of a question provided as an argument.
is_mc_multiple_answeris_matrix_multiple_answeris_text_entry_numericis_text_entry_appendixis_mc_single_answeris_matrix_single_answeris_matrix_bipolaris_multiple_choiceis_single_answeris_rank_orderis_text_entryis_matrix_question
reorganizing_survey_data.R
Qualtrics provides its survey and response data separately, as a QSF and CSV file which
can be downloaded. However, the QualtricsTools application often needs the context of
the data which is included in both and therefore the following functions have been
built to reorganize and combine survey data into structures more usable in R.
Information about survey questions and blocks are pulled from the SurveyElements
list in the Qualtrics QSF file
using valid_questions_blocks_from_survey and add_question_detail.
Response data is linked to its corresponding question with
link_responses_to_questions. Additional functions integrate the questions
and blocks into single lists which contain, for example,
all blocks with all questions inserted into them,
or all questions in a list with nothing else.
get_reorganized_questions_and_blocksvalid_questions_blocks_from_surveyadd_question_detailsplit_sbs_questions_blocksclean_question_textqtype_humannote_text_from_surveyinsert_notes_into_questionsinsert_skiplogic_into_questionssplit_sbs_questionssplit_side_by_side_qsplit_block_elementsinsert_questions_into_blockinsert_questions_into_blockslink_responses_to_questionsclean_html_and_csscreate_question_dictionarycreate_entrylist_of_rows_to_df
uncodeable_question_dictionarylean_responsescreate_entry
answers_from_response_columndisplay_logic_from_questionsplit_respondentscreate_response_column_dictionarycreate_entry
create_question_dictionary_from_qsfcreate_panel_datacreate_merged_response_column
results_generation.R
These functions do the frequency tabling for the given question types. Included in these functions is functionality to look up the "choice text" which corresponds to a response's variable value (depending on things like "RecodedValues," "Choices", "Answers", and so forth), as well as logic which dictates how the frequencies for each response should be tabulated. Finally, the results of gathering this data are then tabled in a data frame which is returned.
percent0which_choices_have_text_entryquestion_variable_to_choice_textgenerate_summary_statsmc_single_answer_resultsmc_multiple_answer_resultsmatrix_single_answer_resultsmatrix_multiple_answer_resultsrename_choicesprocess_question_resultsgenerate_results