Tools for working with the Qualtrics API that prioritize portability, convenience, and security.
This package was inspired by Jasper Ginn’s qualtRics package, and a good deal of the functionality overlaps.
# devtools::install_github("context-dependent/qualtr")
library(qualtr)
library(tidyverse)
Other packages ask you to store sensitive configuration details in
unencrypted yaml files. While this offers the obvious convenience of not
requiring a password, it is insufficiently secure for our needs.
encrypt_conf
asks for your api_token, datacentre url, and key. It
saves these details locally in an encrypted .rds file in the package
root folder. Run the following chunk in the console, replacing the
capitalized parameters with your account’s details
encrypt_conf(
api_token = API_TOKEN,
# base_url = BASE_URL,
key = PASSWORD
)
decrypt_conf
is used internally to decrypt your configuration details,
stored locally in .conf.rds in the package root. You can call it at the
top level to confirm that the credentials are successfully stored.
decrypt_conf()
list_surveys
returns a list of all surveys associated with your API
key.
list_surveys()
By default, more recently edited surveys are displayed first, but if you
pass a search term to list_surveys
, they will be ordered by their
proximity to that.
skills_catalyst_surveys <- list_surveys("Skills Catalyst")
skills_catalyst_surveys
Sometimes, for reasons unknown, list_surveys
does not capture some
surveys. In these cases, you can navigate to the project in the
Qualtrics interface and copy the survey ID from the url.
For the functions in the package that retrieve a survey’s questions or
responses, you can specify the survey either by id, passing it as a
quoted string, or by row in the last result of list_surveys
. In this
case, for example, you could retrieve the same survey by either passing
the number 2 or “SV_0OJXn0xdyrgkl9P”. Examples of use cases presented
later will make the application clear, but generally speaking, it’s ok
to refer to a survey by row number if you’re working with them
interactively, but better to use id if you’re coding its retrieval into
a script.
skills_catalyst_js_exit_responses <- get_responses_v2("SV_0OJXn0xdyrgkl9P")
satisfaction_table_raw <-
skills_catalyst_js_exit_responses %>%
qt_raw(
vars(matches("sat"))
)
satisfaction_table_raw
satisfaction_table_print <-
satisfaction_table_raw %>%
qt_print()
satisfaction_table_print
satisfaction_by_employment_table <-
skills_catalyst_js_exit_responses %>%
rename(employed = attach_4) %>%
group_by(employed) %>%
qt_raw(vars(matches("sat"))) %>%
qt_print()
satisfaction_by_employment_table
skills_catalyst_js_exit_responses %>%
scr_num(
# .vars specifies the variables you want to recode using a tidyselect query
# wrapped in a vars function
.vars = vars(matches("sat_1")),
# .rev specifies, among the variables selected in .vars, which will be reverse coded
# by default, any variable that includes "_r" is reverse coded
# .rev = vars(matches("_r")),
scale = "agree"
) %>%
select(
matches("sat_1")
)
score_scale()
returns a tibble with the items, total, and average
score per item. The .vars
, .rev
, and scale arguments work the same
way.
skills_catalyst_js_exit_responses %>%
score_scale(
var_name = "sat_1",
.vars = vars(matches("sat_1")),
.rev = vars(matches("_r")),
scale = "agree"
)
skills_catalyst_js_exit_questions <- get_survey("SV_0OJXn0xdyrgkl9P")
print_survey(skills_catalyst_js_exit_questions, "prints/2019-02-27_scjs_exit.tex")