---------- Original Message -----------
From: Duncan Temple Lang <duncan@wald.ucdavis.edu> 
To: Ulrike GrБЎmping <groemp@tfh-berlin.de> 
Cc: Uwe Ligges <ligges@statistik.uni-dortmund.de>, r-help@stat.math.ethz.ch 
Sent: Fri, 18 Nov 2005 10:26:51 -0800 
Subject: Re: [R] Method for $

> -----BEGIN PGP SIGNED MESSAGE----- 
> Hash: SHA1 
> 
> Ulrike GrБЎmping wrote: 
> > 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. 
> > 
> 
> For the record, the problem you are experiencing is that 
> you are not using the same argument names in your 
> method as the function "$" uses. Hence there is a mismatch. 
> Use 
> setMethod("$", signature(x="myclass"), function(x, name){ 
> Ба slot(x, name) 
> } ) 
> 
> i.e. rather than slotname as the second argument, use name 
> as that is what $ uses.

Thanks very much for clarifying that. I just wasn't aware of the argument names of $. It's obvious from the help file, once you know what to look for, but ...
> 
> But, as Martin pointed out, this is not an advisable thing 
> to do. 
> And if you want to use an S4 class to house sub-elements, 
> either explicitly specify their types with 
> БаsetClass('myclass', representation( a = "integer", 
> Ба Ба Ба Ба Ба Ба Ба Ба Ба Ба Ба Ба Ба Ба Ба Ба Ба Ба Баb = "matrix", ....) 
> 
> or if you want them to be arbitary objects, then think 
> about why you are using S4.

I have in fact used a class definition like the one you suggest, i.e. have switched from a list to a class by defining an object type for each of my list elements. As a consequence, the former list elements were no longer accessible via "$", which is what I want to recover.
> 
> > 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@statistik.uni-dortmund.de> 
> > To: Ulrike GrБЎmping <groemp@tfh-berlin.de> 
> > Cc: r-help@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@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@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@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 ------- 
> > 
> > ______________________________________________ 
> > 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 
> 
> - -- 
> Duncan Temple Lang Ба Ба Ба Ба Ба Ба Ба Ба duncan@wald.ucdavis.edu 
> Department of Statistics Ба Ба Ба Ба Баwork: Ба(530) 752-4782 
> 371 Kerr Hall Ба Ба Ба Ба Ба Ба Ба Ба Ба Ба fax: Ба (530) 752-7099 
> One Shields Ave. 
> University of California at Davis 
> Davis, CA 95616, USA 
> -----BEGIN PGP SIGNATURE----- 
> Version: GnuPG v1.4.2 (Darwin) 
> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org 
> 
> iD8DBQFDfhzr9p/Jzwa2QP4RAnoPAKCAeNsDpbAC52kfJnmaBdLeGPUTgwCfTqBF 
> Ffg0eMA//XcfzY3kjBqGJ8c= 
> =iO7y 
> -----END PGP SIGNATURE----- 
------- End of Original Message -------

 

	[[alternative HTML version deleted]]


