load_question_types: # - Multiple Answer Questions - mulanswer_questions <-...

View source: R/question_types.R

load_question_typesR Documentation

# — Multiple Answer Questions — mulanswer_questions <- new.env(parent=emptyenv())

Description

#' Multiple Answer questions #' #' Questions where there are checkboxes, and participants can answer multiple answers #' #' #' @param q_name The column name of the attention check question #' @param levels What the different options should be called #' @param options What the options look like in the original data. NULL == autodetect #' #' @export multiple_answer_question <- function(q_name, levels, options=NULL) if (exists(q_name, envir=mulanswer_questions)) warning(paste0(q_name, " is already a multiple answer question. Overwriting...")) assign(q_name, list(levels=levels, options=options), envir=mulanswer_questions)

Usage

load_question_types()

Details

is_multiple_answer_question <- function(column) known_qs <- ls(envir=mulanswer_questions) return(attr(column, "name")

process_multiple_answer_question <- function(column) q_info <- get(attr(column, "name"), envir=mulanswer_questions) out <- stringr::str_split(column, ",") # I have to use an if statement here because factor uses missing() to detect the present of the levels argument # if (!is.null(q_info$options)) # out <- factor(column, levels=q_info$options, labels=q_info$levels) # else # out <- factor(column, labels=q_info$levels) # return(out)


rwash/surveys documentation built on Sept. 18, 2023, 11:31 p.m.