Re: [R] Object attributes in R

From: <dhinds_at_sonic.net>
Date: Thu 12 Oct 2006 - 23:05:10 GMT

dhinds@sonic.net wrote:

> What I've done is to define a subclass that keeps attributes, that can
> be added to any object, shown below. The keep.attr() function is
> supposed to return just user attributes but I'm not sure if my list of
> special ones is complete.

Sorry, the following version should be better.

keep.attr <- function(x)
{

    a <- attributes(x)
    a[c('names','row.names','class','dim','dimnames')] <- NULL     a
}

keep <- function(.Data, ..., .Attr=NULL) {

    cl <- union('keep', class(.Data))
    do.call('structure', c(list(.Data, class=cl, ...), .Attr)) }

'[.keep' <- function(.Data, ...)
keep(NextMethod(), .Attr=keep.attr(.Data))

'[<-.keep' <- function(.Data, ...)
keep(NextMethod(), .Attr=keep.attr(.Data))



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Oct 13 09:13:49 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 13 Oct 2006 - 00:30:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.