Learn R Programming

qualtRics (version 3.1.1)

fetch_survey: Download a survey and import it into R

Description

Download a Qualtrics survey you own via API and import the survey directly into R.

Usage

fetch_survey(surveyID, last_response = NULL, start_date = NULL,
  end_date = NULL, unanswer_recode = NULL, limit = NULL,
  include_questions = NULL, save_dir = NULL, force_request = FALSE,
  verbose = TRUE, label = TRUE, convert = TRUE, import_id = FALSE,
  local_time = FALSE, ...)

Arguments

surveyID

String. Unique ID for the survey you want to download. Returned as id by the all_surveys function.

last_response

String. Export all responses received after the specified response ID. Defaults to NULL.

start_date

String. Filter to only exports responses recorded after the specified date. Accepts dates as character strings in format "YYYY-MM-DD". Defaults to NULL.

end_date

String. Filter to only exports responses recorded before the specified date. Accepts dates as character strings in format "YYYY-MM-DD". Defaults to NULL.

unanswer_recode

String. Recode seen but unanswered questions with a string value. Defaults to NULL.

limit

Integer. Maximum number of responses exported. Defaults to NULL (all responses).

include_questions

Vector of strings (e.g. c('QID1', 'QID2', 'QID3'). Export only specified questions. Defaults to NULL.

save_dir

String. Directory where survey results will be stored. Defaults to a temporary directory which is cleaned when your R session is terminated. This argument is useful if you'd like to store survey results. The downloaded survey will be stored as an RDS file (see readRDS).

force_request

Logical. fetch_survey() saves each survey in a temporary directory so that it can quickly be retrieved later. If force_request is TRUE, fetch_survey() always downloads the survey from the API instead of loading it from the temporary directory. Defaults to FALSE.

verbose

Logical. If TRUE, verbose messages will be printed to the R console. Defaults to TRUE.

label

Logical. TRUE to export survey responses as Choice Text or FALSE to export survey responses as values.

convert

Logical. If TRUE, then the fetch_survey function will convert certain question types (e.g. multiple choice) to proper data type in R. Defaults to TRUE.

import_id

Logical. If TRUE, use Qualtrics import IDs instead of question IDs as column names. Defaults to FALSE.

local_time

Logical. Use local timezone to determine response date values? Defaults to FALSE. See https://api.qualtrics.com/docs/dates-and-times for more information.

...

optional arguments. You can pass all arguments listed in registerOptions (except a different base url / api key). You can also pass a argument 'fileEncoding' (see 'fileEncoding' argument in read_survey) to import your survey using a specific encoding.

See Also

See https://api.qualtrics.com/docs/response-exports for documentation on the Qualtrics API.

Examples

Run this code
# NOT RUN {
# Register your Qualtrics credentials if you haven't already
qualtrics_api_credentials(
  api_key = "<YOUR-API-KEY>",
  base_url = "<YOUR-BASE-URL>"
)

# Retrieve a list of surveys
surveys <- all_surveys()

# Retrieve a single survey
mysurvey <- fetch_survey(surveyID = surveys$id[6])

mysurvey <- fetch_survey(
  surveyID = surveys$id[6],
  save_dir = tempdir(),
  start_date = "2018-01-01",
  end_date = "2018-01-31",
  limit = 100,
  label = TRUE,
  unanswer_recode = "UNANS",
  verbose = TRUE
)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab