sd_add_question {surveydown} | R Documentation |
Add a Question Template to the Current Document
Description
This function inserts a template for a surveydown question at the current cursor position in the active RStudio document. It supports various question types and automatically removes the function call before inserting the template if it exists in the document.
Usage
sd_add_question(type = "mc", id = NULL, label = NULL, chunk = FALSE)
Arguments
type |
A character string specifying the type of question template to
insert.
Default is
|
id |
A character string specifying the ID for the question. If not provided, a default ID based on the question type will be used. This ID should be unique within your survey. |
label |
A character string specifying the label (question text) to display to respondents. If not provided, a default label placeholder will be used. |
chunk |
Logical. If |
Details
The function performs the following steps:
Checks for and removes any existing
sd_add_question()
function call in the document.Inserts the appropriate question template at the current cursor position.
If an ID is provided, replaces the default ID in the template with the provided ID.
If a label is provided, replaces the default label in the template with the provided label.
Value
This function does not return a value. It modifies the active document as a side effect by inserting text and potentially removing a function call.
Examples
if (interactive()) {
library(surveydown)
# Insert a default multiple choice question template
sd_add_question()
# Insert a text input question with custom ID and label
sd_add_question("text", id = "user_email", label = "What is your email address?")
# Insert a slider question template
sd_add_question("slider", id = "satisfaction", label = "How satisfied were you with our service?")
}