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 <[EMAIL PROTECTED]>
To: Ulrike Grömping <[EMAIL PROTECTED]>
Cc: [email protected]
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 [EMAIL PROTECTED], 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){
> > [EMAIL PROTECTED]
> > }
> > )
>
> 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
> >
> > ______________________________________________
> > [email protected] 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 -------
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html