#' Extract form coded string to corresponding levels
#'
#' @param x (chr) a string (i.e. character vector of length one)
#' representing factors' levels in the form of
#' `level1, label1 | level2, label2 | ... | levelN, labelN`
#'
#' @return (chr) a character string of length `N` reporting the label
#' only.
#' @export
#'
#' @examples
#' coded <- "1, maschio | 2, femmina | 3, ambiguo"
#' levels <- str_to_level(coded)
str_to_level <- function(x) {
if (all(is.na(x))) return(character())
checkmate::qassert(x, "s1[1,)")
stringr::str_split(x, " \\| ")[[1]] %>%
stringr::str_remove(pattern = "^.*?, ") %>%
unique()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.