Defines functions select_scores

Documented in select_scores

#' Select scale scores
#' Selects a data frame with score variables generated by score_scale.
#' @param data A data frame
#' @param names_only If TRUE, variable names are returned instead of a data frame
#' @param index_only If TRUE, variable indices are returned instead of a data frame
#' @return A data frame, a vector with variable names or a vector with indices
#' @export
select_scores <- function(data, names_only = FALSE, index_only = FALSE) {

  id <- which(
    sapply(data, function(x) isTRUE(dic_attr(x, .opt$class) == "score"))
  if (names_only) return(names(data)[id])
  if (index_only) return(id)
  data[, id, drop = FALSE]
jazznbass/scaledic documentation built on Sept. 20, 2021, 7:43 p.m.