R/round.R

#' Character-safe rounding
#'
#' Round a vector if it is numeric, but return the original vector if it is character.
#'
#' @param x	a character vector.
#' @param digits integer indicating the number of decimal places.
#' @param ...	arguments to be passed to methods.
#' @return The character vector or the rounded version if numeric.
#'
round_char <- function(x, digits = 0, ...) {
  num_x <- suppressWarnings(as.numeric(x))
  if (is.na(num_x)) return(x)
  round(num_x, digits, ...)
}
debruine/pipeline documentation built on May 8, 2019, 8:59 a.m.