R/utils.max.nchar.R

Defines functions .max_nchar.feR.fable .max_nchar.matrix .max_nchar.numeric .max_nchar.character .max_nchar.vector max_nchar

#' @export
max_nchar <- function(x) {
  # print(class(x))
  # args <- formals(max_nchar)
  # args$x <- x
  # args$DEBUG <- DEBUG
  # do.call(.max_nchar, args)
  UseMethod(".max_nchar",x)
}


.max_nchar.vector <- function(x) {
  # DEBUG = attr(x,"DEBUG")
#
#   cat("\n--------------\n")
#   print(x)
#   print(max(nchar(x, type = "width"),na.rm=TRUE))
  # cat("\n--------------\n")
  # if(DEBUG) cat("\n .max_nchar VECTOR\n")
  as.numeric(max(nchar(x, type = "width"),na.rm=TRUE))
}

.max_nchar.character <- function(x) {
  # if(DEBUG) cat("\n .max_nchar CHARACTER\n")
  .max_nchar.vector(x)
}

.max_nchar.numeric <- function(x) {
  # if(DEBUG) cat("\n .max_nchar NUMERIC\n")
  .max_nchar.vector(sprintf("%s",x))
}

.max_nchar.matrix <- function(x) {
  # DEBUG = attr(x,"DEBUG")
  # if(DEBUG) cat("\n .max_nchar MATRIX\n")

  if (nrow(x) > 1) as.numeric(apply(x,2,function(x) max(nchar(x, type = "width"),na.rm=TRUE)))
  else .max_nchar.vector(x)
}

.max_nchar.feR.fable <- function(x) {
  # if(DEBUG) cat("\n .max_nchar FABLE\n")
  .max_nchar.matrix(x)
}
feranpre/feR documentation built on Nov. 22, 2022, 2:29 a.m.