#' 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, ...)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.