RE: [R] How to change the value of a class slot

From: Ross Boylan <ross_at_biostat.ucsf.edu>
Date: Wed 08 Jun 2005 - 04:36:17 EST

On Mon, 2005-06-06 at 14:15 -0700, Berton Gunter wrote:
> I'm puzzled:
>
> > It looks as if instances of class objects are best thought of as
> > immutable once created.
> >
>
> what then is setReplaceMethod() for?
assignment operators do the whole object replacement behind the scenes, at least conceptually, as far as I can tell. I agree: they are mutators. But outside of this special case, it seems mutation of slots is difficult (i.e., requires the assistance of the caller).

By the way, the documentation on setReplaceMethod does not actually say what it does. I found out by looking at the code.

Second, in my experiments I couldn't get setReplacementMethod to work:

"bumpIndex<-" <- function(pm, value) {
  pm@i <- pm@i+as.integer(value)
  pm
}

# I get an error without the next function definition bumpIndex <- function(pm) pm@i

setReplaceMethod("bumpIndex",

                 signature=signature(pm="CompletePathMaker",
                   value="numeric"), bumpIndex) 

When I try to load this, I get

arguments in definition changed from (spec) to (object)
arguments in definition changed from (self) to (object)
arguments in definition changed from (self) to (object)
Creating a new generic function for 'bumpIndex<-' in '.GlobalEnv' Error in conformMethod(signature, mnames, fnames, f) :

        In method for function "bumpIndex<-": formal arguments omitted in the method definition cannot be in the signature (value = "numeric")

All the errors are triggered by setReplaceMethod. Can anyone help me interpret them? Or, maybe better, tell me how to debug the "compilation"?

> I leave it to language "experts" to say whether S4 formal classes and
> methods are wise or not in comparison to others. From my fairly ignorant
> perspective, that always seems to be a matter of taste.

There are actually two related issues on that score: first, whether the complex of expectation set up by talking about "objects" and "classes" are met by what R/S does, and second the wisdom of what R/S does in its own right.

>
> Cheers,
> Bert
>
>

-- 
Ross Boylan                                      wk:  (415) 502-4031
530 Parnassus Avenue (Library) rm 115-4          ross@biostat.ucsf.edu
Dept of Epidemiology and Biostatistics           fax: (415) 476-9856
University of California, San Francisco
San Francisco, CA 94143-0840                     hm:  (415) 550-1062

______________________________________________
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
Received on Wed Jun 08 04:43:34 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:27 EST