Does that mean, then, that the help page's "x$name" just accidentally coincides with the arguments x and name that the "$"-function requires in S4?

Regards, Ulrike

---------- Original Message -----------
From: Prof Brian Ripley <ripley@stats.ox.ac.uk> 
To: Ulrike GrБЎmping <groemp@tfh-berlin.de> 
Cc: Duncan Temple Lang <duncan@wald.ucdavis.edu>, r-help@stat.math.ethz.ch 
Sent: Tue, 22 Nov 2005 08:39:32 +0000 (GMT) 
Subject: Re: [R] Method for $

> On Fri, 18 Nov 2005, Ulrike GrБЎmping wrote: 
> 
> > From: Duncan Temple Lang <duncan@wald.ucdavis.edu> 
> 
> [...] 
> >> 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 ... 
> 
> `For the record', this is rather misleading. Ба$ is a primitive function in 
> R, and does _not_ have argument names (it uses only positional matching 
> like all primitive functions). БаTo check this, try 
> 
> xx <- list(a=1, b=2) 
> `$`(y=xx, zz="b") 
> 
> which is perfectly valid R and works just like xx$b. БаHence there is no 
> reason for the help page to specify argument names (and it does in fact 
> explain that they are not used). 
> 
> However, the S4 model needs argument names, and so when setting S4 methods 
> for primitive functions one needs to use the argument names which it 
> _assumes_. БаSometimes the only way to find those out is to read the code. 
> They are in src/library/methods/R/BasicFunsList.R which contains 
> 
> "$" = function(x, name) 
> { 
> Ба Ба name <- as.character(substitute(name)) 
> Ба Ба standardGeneric("$") 
> } 
> 
> S3 methods for primitives do not need to match argument names, fortunately 
> as Duncan TL has just added an S3 method with the (mis-matching) arguments 
> 
> > args(`$.DLLInfo`) 
> function (x, i, ...) 
> 
> Since there are no argument names for the generic, the QC tools do not 
> check such cases. 
> 
> -- 
> Brian D. Ripley, Ба Ба Ба Ба Ба Ба Ба Ба Ба ripley@stats.ox.ac.uk 
> Professor of Applied Statistics, Баhttp://www.stats.ox.ac.uk/~ripley/ 
> University of Oxford, Ба Ба Ба Ба Ба Ба Tel: Ба+44 1865 272861 (self) 
> 1 South Parks Road, Ба Ба Ба Ба Ба Ба Ба Ба Ба Ба +44 1865 272866 (PA) 
> Oxford OX1 3TG, UK Ба Ба Ба Ба Ба Ба Ба БаFax: Ба +44 1865 272595 
------- End of Original Message -------

 

	[[alternative HTML version deleted]]


