[Rd] suggestion for update.default

Mark.Bravington at csiro.au Mark.Bravington at csiro.au
Fri Feb 20 07:19:33 MET 2004


'update.default( x, ...)' checks for a component of 'x' named 'call' and gives up if there isn't one. Before giving up, how about checking for an attribute named 'call'?

I.E. something like this: 
    # Existing code:
    call <- object$call

    # Suggested insertion:
    if (is.null(call))
      call <- attr( object, 'call')

    # Existing code:
    if( is.null( call))
stop("need an object with call component or attribute") # slight mod

Why would anyone store the call as an attribute, you may ask? Well, I often find it useful to write code that returns a data.frame, which would be corrupted by adding a 'call' component-- but I still want to record how the object was generated, so I use a 'call' attribute instead. Of course it would be possible to extend the object's class to inherit from 'data.frame' and write an 'update' method for that class, but that seems like overkill.

Mark



*******************************

Mark Bravington
CSIRO (CMIS)
PO Box 1538
Castray Esplanade
Hobart
TAS 7001

phone (61) 3 6232 5118
fax (61) 3 6232 5012
Mark.Bravington at csiro.au



More information about the R-devel mailing list