#' Check whether a character vector has unique entries
#' Return 1 if the vector is unique else 0
#' @param inp_vec (character) : A character vector to check for uniqueness
#'
#' @export
check_isunique <- function(inp_vec){
(length(inp_vec) == length(unique(inp_vec))) %>%
base::as.integer() %>%
base::return()
}
#' Alphabetically sort a single string (character vector with one element)
#'
#' @param inp_vec (character) : A character vector with a single element
#'
#' @export
sort_string <- function(inp_vec){
inp_vec %>%
stringr::str_split(string = ., pattern = "") %>%
base::unlist() %>%
base::sort() %>%
stringr::str_c(... = ., collapse = "") %>%
base::return()
}
#' Split a given string into individual characters
#'
#' @param inp_vec (character) : A character vector (string) to split into
#' individual characters
#' @param ptrn (character) : A delimiter used to split the string - the default
#' is a blank string so that this input string is split into individual
#' characters
#'
#' @export
split_string <- function(inp_vec, ptrn = ""){
inp_vec %>%
stringr::str_split(string = ., pattern = ptrn) %>%
base::return()
}
#' Concatenate a vector of strings into a single character vector (string)
#'
#' @param inp_vec (character) : A character vector of strings to concatenate
#' into a single string
#' @param ptrn (character) : A delimiter used to combine the string - the
#' default is a blank string so that this input string is combined
#' into a single character vector (string)
#'
#' @export
concat_string <- function(inp_vec, ptrn = ""){
inp_vec %>%
stringr::str_c(... = ., collapse = ptrn) %>%
base::return()
}
#' Sort individual strings in a vector of strings
#'
#' @param inp_vec (character) : A character vector of strings to sort
#' individually
#'
#' @export
sort_ind_str <- function(inp_vec){
inp_vec %>%
purrr::map(.x = ., .f = split_string) %>%
purrr::map(.x = ., .f = unlist) %>%
purrr::map(.x = ., .f = sort) %>%
purrr::map(.x = ., .f = concat_string) %>%
base::unlist() %>%
base::return()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.