qualtRics 1.0 now available from CRAN

April 26, 2017

(This article was first published on Jasper Ginn's blog, and kindly contributed to R-bloggers)

Qualtrics allows users to collect online data through surveys. My R package qualtRics contains convenience functions to pull survey results straight into R using the Qualtrics API instead of having to download survey results manually.

Currently, the package contains three functions:

  1. getSurveys() fetches a list of all surveys that you own or have access to from Qualtrics.
  2. getSurvey() downloads a survey from Qualtrics and loads it into R.
  3. readSurvey() allows you to read CSV files you download manually from Qualtrics.

Getting started with the package is straightforward. Note that your institution must support API access and that it must be enabled for your account. Whoever manages your Qualtrics account can help you with this. Refer to the Qualtrics documentation to find your API token.


Register your Qualtrics API key. You need to do this once every R session:

registerApiKey(API.TOKEN = "")

Get a data frame of all surveys to which you have access:

surveys <- getSurveys(root_url="https://leidenuniv.eu.qualtrics.com") # URL is for my own institution

Export a survey and load it into R:

mysurvey <- getSurvey(surveyID = surveys$id[6],
                      root_url = "https://leidenuniv.eu.qualtrics.com",
                      verbose = TRUE)

You can add a from/to date to only retrieve responses between those dates:

surv <- getSurvey(survs$id[4],
                  root_url = "https://leidenuniv.eu.qualtrics.com",
                  startDate = "2016-09-18",
                  endDate = "2016-10-01",
                  useLabels = FALSE,
                  verbose = TRUE)

You may also reference a response ID. getSurvey will then download all responses that were submitted after that response:

surv <- getSurvey(survs$id[4],
                  root_url = "https://leidenuniv.eu.qualtrics.com",
                  lastResponseId = "R_3mmovCIeMllvsER",
                  useLabels = FALSE,
                  verbose = TRUE)

You can store the results in a specific location if you like:

mysurvey <- getSurvey(surveyID = surveys$id[6],
                      save_dir = "/users/jasper/desktop/",
                      root_url = "https://leidenuniv.eu.qualtrics.com",
                      verbose = TRUE)

Note that surveys that are stored in this way will be saved as an RDS file rather than e.g. a CSV. Reading an RDS file is as straightforward as this:

mysurvey <- readRDS(file = "/users/jasper/desktop/mysurvey.rds")

You can read a survey that you downloaded manually using readSurvey:

mysurvey <- readSurvey("/users/jasper/desktop/mysurvey.csv")

To avoid special characters (mainly periods) in header names, readSurvey uses question labels as the header names. The question belonging to that label is then added using the sjmisc package. Qualtrics gives names to these labels automatically, but you can easily change them.

If you have any questions or feature requests, please leave them here.

To leave a comment for the author, please follow the link and comment on their blog: Jasper Ginn's blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)