R/preserve_attributes.R

Defines functions preserve_attributes

Documented in preserve_attributes

#' Return a subset of the attributes as a list
#' 
#' @param x The object to extract attributes from
#' @param which A character string of attributes to preserve
#' @param value A named list to assign into the attributes of \code{x}
#' @return A list of attributes
#' @export
preserve_attributes <- function(x, which) {
  attributes(x)[which]
}

#' @describeIn preserve_attributes Assign a subset of attributes to an object
#' @export
"preserve_attributes<-" <- function(x, value) {
  for (n in names(value)) {
    attr(x, n) <- value[[n]]
  }
  x
}
billdenney/pknca.portation documentation built on May 3, 2019, 2:55 p.m.