R/strPadLeft.R

Defines functions strPadLeft

Documented in strPadLeft

#' Left pad strings.
#'
#' Left pad strings.
#' @export strPadLeft
#' @author Tokhir Dadaev


strPadLeft <- function(labels, width = 15, pad = " "){
  # ref: Used to left pad strings for manhattan plot on Yaxis.
  
  #ensure 1 nchar
  pad <- substr(pad,1,1)
  
  # left pad with pad character
  x <- paste0(sapply(width - ifelse(nchar(labels) > width,
                                    width,
                                    nchar(labels)),
                     function(i) paste0(rep(pad,i), collapse = "")),
              labels)
  
  #cut longer than width vars
  return(substr(x, 1, width))
}
oncogenetics/oncofunco documentation built on March 9, 2024, 5:23 p.m.