Description Usage Arguments Details Value Examples
View source: R/construct_question.R
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()
.
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"
)
|
df |
|
question_text |
variable name (unquoted) with the question text |
language |
variable name (unquoted) with the language code |
choices |
variable name (unquoted) with the choice |
answers |
variable name (unquoted) with the answer |
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" |
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:
Sequential numbering: Q1, Q2, ...
Block numbering: Q1.1, Q1.2... (Block 1); Q2.1, Q2.2, ... (Block 2)
Internal ID numbering: QID1, QID2, ...
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.
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:
MC : Multiple/single choice question
Matrix : Multiple choice, multiple answer question
TE : Text entry question
DB : Descriptive text only (no choices/answers)
Please note, that all questions with question_type=MC
are single choice by default. See update_question
for examples on how to change that.
List of survey elements.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.