[R] Method for $
Ulrike Grömping
groemping at tfh-berlin.de
Fri Nov 18 18:35:23 CET 2005
Uwe,
thank thank you very much for your suggestion. This does in fact work, if I
define
"$.myclass"<-function(x,slotname){slot(x,slotname)}
which solves my immediate need.
However, the setMethod version
setMethod("$", signature(x="myclass"), function(x,slotname){
slot(x,slotname)
}
)
still produces the same error message as before (cf. below). If anyone has a
solution for this, I would appreciate it.
Uwe, my best wishes also to Dortmund and Lena, and by the way, it's your book
that got me started with understanding (part of) the programming aspects of R
relatively fast.
Regards,
Ulrike Grömping
---------- Original Message -----------
From: Uwe Ligges <ligges at statistik.uni-dortmund.de>
To: Ulrike Grömping <groemp at tfh-berlin.de>
Cc: r-help at stat.math.ethz.ch
Sent: Fri, 18 Nov 2005 17:45:40 +0100
Subject: Re: [R] Method for $
> Ulrike Grömping wrote:
>
> > Dear R experts,
> >
> > I have defined a class "myclass" and would like the slots to be
extractable
> > not only by "@" but also by "$". I now try to write a method for "$" that
> > simply executes the request object at slotname, whenever someone calls
> > object$slotname for any object of class "myclass".
> > I don't manage to find out how I can provide this function
with "slotname",
> > so that one and the same function works for any arbitrary slotname a user
> > might choose.
> >
> > I have tried
> >
> > setMethod("$", signature(x="myclass"), function(x,slotname){
> > x at slotname
> > }
> > )
>
> Ulrike,
>
> what about (untested!):
> slot(x, slotname)
>
> Best wishes from Dortmund and Lena,
> Uwe Ligges
>
> > This produced the error message:
> > In method for function "$": expanding the signature to
> > include omitted arguments in definition: name = "missing"
> > Error in rematchDefinition(definition, fdef, mnames, fnames, signature) :
> > methods can add arguments to the generic only if '...' is an
argument
> > to the generic
> >
> > My searches for a solution of this problem have not been successful. Can
> > someone help?
> >
> > Thanks and regards,
> > Ulrike Grömping, Berlin
> >
> > ______________________________________________
> > R-help at 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
------- End of Original Message -------
More information about the R-help
mailing list