[R] Method for $

Ulrike Grömping groemping at tfh-berlin.de
Fri Nov 18 15:37:58 CET 2005


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

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




More information about the R-help mailing list