R/leftright.R

Defines functions left right

Documented in left right

#' Left Right
#'
#' R functions mirroring Excel's left() and right() functions.
#'
#' @param string Character string to pull from.
#' @param num_chars Number of characters to pull.
#'
#' @name leftright
#'
#' @return Adjusted character string.
#'
#' @examples
#' left("leftright", 4)
#' right("leftright", 5)
NULL

#' @rdname leftright
#' @export
left <- function(string, num_chars) {
  substr(string, 1, num_chars)
}

#' @rdname leftright
#' @export
right <- function(string, num_chars) {
  substr(string, nchar(string) - (num_chars - 1), nchar(string))
}
jimbrig2011/arsenal documentation built on July 12, 2019, 12:25 p.m.