QualtricsTools not only makes it easy to create reports of text appendices, but also to create text appendices with frequency reports of categorized "coded comments." The coded comments must follow a standardized format, containing the "ResponseID" in the first column, and a column titled "varname" past which each column title represents a category which have "1" entries in cells to represent a respondent's response being categorized into the given category.

An example of a coded comments document is included in the QualtricsTools package. In the prescribed workflow, each individual text entry component of a survey which needs to be categorized must have a corresponding coded comments xlsx file in a directory. However, in this example we will only use coded comments for a single text entry component.

First, let's download the data into a directory.

library(shiny)
library(QualtricsTools)
library(RCurl)

# Grab the sample survey data from our repository.
qsf <- getURL("https://raw.githubusercontent.com/emmamorgan-tufts/QualtricsTools/master/data/Sample%20Surveys/Better%20Sample%20Survey/Better_Sample_Survey.qsf")
csv <- getURL("https://raw.githubusercontent.com/emmamorgan-tufts/QualtricsTools/master/data/Sample%20Surveys/Better%20Sample%20Survey/Better_Sample_Survey.csv")

# Write the sample survey data to file.
qsf_tempfile_path = tempfile()
csv_tempfile_path = tempfile()
write(x = qsf, file = qsf_tempfile_path)
write(x = csv, file = csv_tempfile_path)

# Download the sample coded comments
url <- "https://github.com/emmamorgan-tufts/QualtricsTools/blob/master/data/Sample%20Surveys/Comment%20Coding/Coded%20Comments/Q5%20Coded.xlsx?raw=true"
coded_comments_directory <- file.path(tempdir(), basename(tempfile(pattern="")))
dir.create(path = coded_comments_directory)
filename <- "Q5 Coded.xlsx"
coded_comments_filepath <- file.path(coded_comments_directory, filename)
download.file(url, coded_comments_filepath, mode="wb")

Just to make clear what the formatting of the Coded Comments should be, here's the file we just downloaded.

df <- readxl::read_xlsx(coded_comments_filepath)
options(knitr.kable.NA = '')
knitr::kable(df, format='markdown')
output_filepath <- make_coded_comments(
  qsf_path = qsf_tempfile_path,
  csv_path = csv_tempfile_path,
  headerrows = 3, 
  sheets_dir = coded_comments_directory,
  n_threshold = 0,
  filename = "ExampleHTMLCodedComments.html"
)
# We use the includeHTML function from the shiny package to 
# render the HTML output.
includeHTML(output_filepath)

The n_threshold parameter which is passed above as 0 is the threshold for which coded comments frequency tables with a total number of responses less than n_threshold are not included. The parameter defaults to 15 if it is not specified. For example, when we render the report with the n_threshold = 15 default parameter we see that the coded comments frequency table is not included in the report:

output_filepath <- make_coded_comments(
  qsf_path = qsf_tempfile_path,
  csv_path = csv_tempfile_path,
  headerrows = 3, 
  sheets_dir = coded_comments_directory,
  filename = "ExampleHTMLCodedComments.html"
)

shiny::includeHTML(output_filepath)


ctesta01/QualtricsTools documentation built on May 14, 2019, 12:27 p.m.