R/htmlTable_helpers_convertDfFactors.R

Defines functions prConvertDfFactors

Documented in prConvertDfFactors

#' Convert all factors to characters to print them as they expected
#'
#' @inheritParams htmlTable
#' @return The data frame with factors as characters
prConvertDfFactors <- function(x) {
  if (!"data.frame" %in% class(x)) {
    return(x)
  }

  i <- sapply(x, function(col) {
    (
      (
        !is.numeric(col) &&
          !is.character(col)
      ) ||
        (
          inherits(col, "times") # For handlin Chron input
        )
    )
  })

  if (any(i)) {
    x[i] <- lapply(x[i], as.character)
  }

  return(x)
}

Try the htmlTable package in your browser

Any scripts or data that you put into this service are public.

htmlTable documentation built on Sept. 11, 2024, 8:48 p.m.