R/misc.R

Defines functions copy_attrs clean_message as.data.table.treeprof_fun_table as.dt

Documented in as.data.table.treeprof_fun_table as.data.table.treeprof_fun_table as.dt clean_message

#' Convert a Treeprof object to `data.table`
#'
#' Primarily used to display the underlying \code{`data.table`} structure of a
#' \code{`treeprof`} object
#'
#' @export
#' @aliases as.data.table.treeprof_fun_table
#' @param x a \code{`treeprof`} object
#' @return a \code{`data.table`} object

as.dt <- function(x, keep.rownames=FALSE) {
  x.cp <- copy(x)
  setattr(x.cp, "class", class(x)[-grep("^treeprof", class(x))])
  x.cp
}
#' @export

as.data.table.treeprof_fun_table <- function(x, keep.rownames=FALSE) {
  x.cp <- copy(x)
  setattr(x.cp, "class", class(x)[-grep("^treeprof", class(x))])
  x.cp
}

#' Outputs a Message For Overwriting
#'
#' @keywords internal
#' @param msg character
#' @param verbose logical(1L)

clean_message <- function(msg, verbose) {
  if(verbose) cat(msg, "\n", sep="", file=stderr())
}

#' Copies Attributes Lost With `[`
#'
#' Modifies \code{target} by reference.  Only copies a subset of attributes as
#' often it doesn't make sense to copy row names, etc.
#'
#' @keywords internal

copy_attrs <- function(target, current) {
  setattr(target, "meta.data", attr(current, "meta.data"))
  setattr(target, "time.unit", attr(current, "time.unit"))
  setattr(target, "class", class(current))
}
brodieG/treeprof documentation built on Nov. 11, 2021, 1:36 a.m.