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

From: Berton Gunter <>
Date: Wed 08 Jun 2005 - 06:49:58 EST

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

'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.

> 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
> Dept of Epidemiology and Biostatistics fax: (415) 476-9856
> University of California, San Francisco
> San Francisco, CA 94143-0840 hm: (415) 550-1062
> mailing list PLEASE do read the posting guide! Received on Wed Jun 08 06:55:53 2005

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