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)
}
gforge/htmlTable documentation built on Nov. 4, 2023, 12:05 a.m.