[R] Object attributes in R
dhinds at sonic.net
dhinds at sonic.net
Fri Oct 13 01:05:10 CEST 2006
dhinds at 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.
-- David Hinds
----------------
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))
More information about the R-help
mailing list