R/margonize.R

#' Margonize
#'
#' "Interesting capitalization", I said.
#' "Yeah. I'm a big believer in random capitalization.
#' The rules of capitalization are so unfair to words in the middle.", Margo said.
#'
#' @param string The string you wish to margonize
#'
#' @return A margnoized string
#' @export
#'
#' @examples margonize("Sebastian is awesome!")
margonize <- function(string) {

    string <- unlist(stringr::str_split(string, ""))

    string <- lapply(string, function(char) {

        if (runif(1) >= 0.5) {

            char <- stringr::str_to_lower(char)

        } else {

            char <- stringr::str_to_upper(char)

        }

        return(char)
    })

    string <- do.call(c, string)
    string <- stringr::str_c(string, collapse = "")

    return(string)
}
Steensson/valhalla documentation built on May 6, 2019, 5:59 p.m.