construct_question: Constructs a survey question from a data frame

Description Usage Arguments Details Value Examples

View source: R/construct_question.R

Description

This function takes a nested tibble representing a survey question and converts it into a survey questions that can be added to a qsf file using the append_survey() function. The function does the opposite of get_questions().

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
construct_question(
  df,
  question_text,
  language,
  choices = NULL,
  answers = NULL,
  master = "EN",
  question_id = "Q1",
  primary_attribute = "Q1",
  secondary_attribute = "New question",
  data_export_tag = "Q1",
  question_description = "first_question",
  question_type = "MC"
)

Arguments

df

tibble

question_text

variable name (unquoted) with the question text

language

variable name (unquoted) with the language code

choices

variable name (unquoted) with the choice tibble (default: NULL)

answers

variable name (unquoted) with the answer tibble (default: NULL)

master

language code of master language (default: "EN")

question_id

question ID (default: Q1)

primary_attribute

primary attribute string (default: Q1)

secondary_attribute

secondary attribute string (default: "new question")

data_export_tag

data export tag (default: Q1)

question_description

question description

question_type

either "MC", "TE", "DB", or "Matrix"

Details

The argument choice can be left empty (NULL) and will be ignored if question_type='DB'. The argument answer must be supplied if question_type='Matrix'.

The tibble for choice and answer must include two: a column with numeric IDs determining the display order and the a column with the labels for each choice. The column names are ignored.

For surveys constructed via the online editor, primary_attribute and question_id are typically identical and can not be modified by the user. The argument question_id must be unique within the survey and follow one of three schemes:

For sequential and block numbering "Q" can be replaced by any other capitalized letter from the Latin alphabet. When using write_qsf these conventions are checked.

Screenshot Qualtrics online editor

The argument secondary_attribute controls the question label shown in the online editor. In the picture above, "sex" is the question label. The argument data_export_tag controls the name of the variable in the csv file with the collected survey data. When constructing a survey via the online editor, the data_export_tag is identical to question_id as long as the user doesn't modify. In the picture above, the data export tag is "Q1".

The argument question_type must be one of four options:

Please note, that all questions with question_type=MC are single choice by default. See update_question for examples on how to change that.

Value

List of survey elements.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
q <- tibble(
		QuestionText="How can we contact you?",
		Choices = list(tibble(
					id=c(1,2),
					label=c("Email","SMS"))),
		Language = "EN"
		)

sq <- construct_question(q, 
    question_text=QuestionText, 
    choices=Choices, 
    language=Language, 
    master="EN",  
    question_id="Q1",
    primary_attribute="Q1",
    secondary_attribute="contact",
    data_export_tag="contact", 
    question_description="Contact question", 
    question_type = "MC") 

qsf <- create_survey(sq)

sumtxt/qsf documentation built on Nov. 22, 2021, 9:31 p.m.