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.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_sheets
  • get_coded_comment_sheet
  • get_coded_comment_sheet_fmp
  • get_coded_comment_sheet_NVivo
  • format_coded_comments_fmp
  • format_coded_comments_NVivo
  • format_coded_comment_sheets
  • merge_split_column_into_comment_sheet
  • format_and_split_comment_sheets
  • insert_coded_comments
  • insert_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.

  • repath
  • question_from_response_column
  • choice_text_from_question
  • app
  • get_setup
  • find_question
  • find_question_index
  • find_question_index_by_qid
  • choice_text_from_response_column
  • blocks_header_to_html
  • number_of_blocks
  • questions_from_blocks
  • flow_from_survey
  • get_setup_in_environment
  • make_results_tables
  • make_text_appendices
  • make_coded_comments
  • make_split_results_tables
  • make_split_text_appendices
  • make_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_tables
  • question_description
  • has_display_logic
  • text_appendices_table
  • uncodeable_questions_message
  • tabelize_display_logic
  • appendix_lettering
  • table_html_coded_comments
  • table_no_respondents
  • table_text_entry
  • table_non_text_entry
  • table_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_data
  • load_qsf_data
  • ask_for_qsf
  • ask_for_csv
  • validate_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_answer
  • is_matrix_multiple_answer
  • is_text_entry_numeric
  • is_text_entry_appendix
  • is_mc_single_answer
  • is_matrix_single_answer
  • is_matrix_bipolar
  • is_multiple_choice
  • is_single_answer
  • is_rank_order
  • is_text_entry
  • is_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_blocks
  • valid_questions_blocks_from_survey
  • add_question_detail
  • split_sbs_questions_blocks
  • clean_question_text
  • qtype_human
  • note_text_from_survey
  • insert_notes_into_questions
  • insert_skiplogic_into_questions
  • split_sbs_questions
  • split_side_by_side_q
  • split_block_elements
  • insert_questions_into_block
  • insert_questions_into_blocks
  • link_responses_to_questions
  • clean_html_and_css
  • create_question_dictionary
    • create_entry
    • list_of_rows_to_df
  • uncodeable_question_dictionary
  • lean_responses
    • create_entry
  • answers_from_response_column
  • display_logic_from_question
  • split_respondents
  • create_response_column_dictionary
    • create_entry
  • create_question_dictionary_from_qsf
  • create_panel_data
  • create_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.

  • percent0
  • which_choices_have_text_entry
  • question_variable_to_choice_text
  • generate_summary_stats
  • mc_single_answer_results
  • mc_multiple_answer_results
  • matrix_single_answer_results
  • matrix_multiple_answer_results
  • rename_choices
  • process_question_results
  • generate_results