Skip to contents

This function allows storing additional values to be included in the survey data, such as respondent IDs or other metadata.

Usage

sd_store_value(value, id = NULL)

Arguments

value

The value to be stored. This can be any R object that can be coerced to a character string.

id

(Optional) Character string. The id (name) of the value in the data. If not provided, the name of the value variable will be used.

Value

NULL (invisibly)

Examples

if (interactive()) {
  library(surveydown)

  # Get path to example survey file
  survey_path <- system.file("examples", "sd_ui.qmd",
                             package = "surveydown")

  # Copy to a temporary directory
  temp_dir <- tempdir()
  file.copy(survey_path, file.path(temp_dir, "basic_survey.qmd"))
  orig_dir <- getwd()
  setwd(temp_dir)

  # Define a minimal server
  server <- function(input, output, session) {

    # Create a respondent ID to store
    respondentID <- 42

    # Store the respondentID
    sd_store_value(respondentID)

    # Store the respondentID as the variable "respID"
    sd_store_value(respondentID, "respID")

    sd_server()
  }

  # Run the app
  shiny::shinyApp(ui = sd_ui(), server = server)

  # Clean up
  setwd(orig_dir)
}