R/str_funs.R

Defines functions str_to_link str_underscore str_trim

Documented in str_to_link str_trim str_underscore

#' Trim white spaces
#'
#' Returns string w/o leading or trailing whitespace.
#' @param x A character vector.
#'
#' @export
#'
str_trim <- function(x) gsub("^\\s+|\\s+$", "", x)

#' Replace white space(s)with underscore
#'
#' Returns string separated by underscore.
#' @param x A character vector.
#' @export
#'
str_underscore <- function(x) gsub('([[:punct:]])|\\s+', '_', x)

#' Convert string to HTML link
#'
#' @param web.link The embedded web link.
#' @param display The text for the hyperlink.
#' @param new.tab Should the link be opened in a new tab in the browser?
#'
#' @export
str_to_link <- function(web.link, display, new.tab = TRUE) {

  if (new.tab)
    paste0("<a href='", web.link, "' target = '_blank'>", display, "</a>") else
      paste0("<a href='", web.link, "'>", display, "</a>")

}
MohoWu/ricardor documentation built on March 24, 2022, 4:39 p.m.