Learn R Programming

surveydown (version 0.5.0)

sd_add_question: 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", chunk = FALSE)

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.

Arguments

type

A character string specifying the type of question template to insert. Default is "mc" (multiple choice). Available options are:

  • "mc": Multiple choice (single selection)

  • "select": Dropdown selection

  • "mc_multiple": Multiple choice (multiple selections)

  • "mc_buttons": Multiple choice with button layout (single selection)

  • "mc_multiple_buttons": Multiple choice with button layout (multiple selections)

  • "text": Short text input

  • "textarea": Long text input

  • "numeric": Numeric input

  • "slider": Slider input

  • "date": Date input

  • "daterange": Date range input

chunk

Logical. If TRUE, the code will be generated with the R code chunk wrapper. Defaults to FALSE.

Details

The function performs the following steps:

  1. Checks for and removes any existing sd_add_question() function call in the document.

  2. Inserts the appropriate question template at the current cursor position.

Examples

Run this code
if (interactive()) {
  library(surveydown)

  # Insert a default multiple choice question template
  sd_add_question()

  # Insert a text input question template
  sd_add_question("text")

  # Insert a slider question template
  sd_add_question("slider")
}

Run the code above in your browser using DataLab