R/difficulty.R

Defines functions format_difficulty

Documented in format_difficulty

# Functions to process and display difficulty levels.

#' @rdname format_difficulty
#' @export
#' @format
#' `difficulty_levels` is a character vector of valid difficulty levels.
"difficulty_levels"

difficulty_levels <- c("Novice", "Intermediate", "Advanced")

#' Challenge Difficulty Levels
#'
#' @param params Challenge parameters as `list`.
#'
#' @return
#' `format_difficulty()` returns a character value indicating the challenge difficulty.
#' @export
#'
#' @importFrom stringr str_to_title
#'
#' @examples
#' difficulty_levels
#'
#' params <- list(difficulty = "novice")
#' cat(format_difficulty(params))
format_difficulty <- function(params) {
    difficulty <- params$difficulty
    if (is.null(difficulty)) {
        stop("Challenge difficulty is missing")
    }
    difficulty <- str_to_title(difficulty)
    if (!difficulty %in% difficulty_levels) {
        stop("Challenge difficulty should be one of ", deparse(difficulty_levels))
    }
    difficulty
}
kevinrue/BiocChallenges2 documentation built on Nov. 2, 2021, 7:49 a.m.