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

Berton Gunter gunter.berton at gene.com
Tue Jun 7 22:49:58 CEST 2005


> Second, in my experiments I couldn't get setReplacementMethod to work:
> 
> "bumpIndex<-" <- function(pm, value) {
>   pm at i <- pm at i+as.integer(value)
>   pm
> }
> 
> # I get an error without the next function definition
> bumpIndex <- function(pm) pm at i
> 
> setReplaceMethod("bumpIndex",
>                  signature=signature(pm="CompletePathMaker",
>                    value="numeric"), bumpIndex) 
> 


'bumpIndex' is apparently not a generic function (created by setGeneric)
signature is not an argument to setReplaceMethod 
The ... argument to setReplaceMethod must include a function to do the
replacement, which is why you need the bumpIndex function (I agree that this
is not cleanly documented, but it's fairly easy to see since
setReplaceMethod calls setMethod and that requires the function argument).

so I don't see why you expect this to work at all. At the very least,
shouldn't you do what the documentation tells you to? I think that you are
expecting R to work according to your paradigm rather than trying to
understand how it actually works. If you feel that R's paradigm (and/or
documentation) is too awful to bother with, you might consider the R.oo
package, which does OOP an entirely different way.

-- Bert Gunter



> 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 at 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
> 
>




More information about the R-help mailing list