From marc_schwartz at me.com  Fri Jul  9 14:58:51 2010
From: marc_schwartz at me.com (Marc Schwartz)
Date: Fri, 09 Jul 2010 07:58:51 -0500
Subject: [Rd] Defining a method that behaves like '$'?
In-Reply-To: <4C371AE3.9060801@cbio.uct.ac.za>
References: <4C371398.80603@cbio.uct.ac.za> <4C371645.6030204@gmail.com>
	<4C371AE3.9060801@cbio.uct.ac.za>
Message-ID: <8D37932C-62F7-44C0-BAFA-9A77ABADE59F@me.com>

You were, in effect, trying to overload the ":" operator, which is of course for defining sequences.

If you are using S4 methods, what is wrong with using the default "@" as the extraction syntax (eg. a at name) to get at slots?

See ?"@" and ?slot

HTH,

Marc Schwartz

On Jul 9, 2010, at 7:49 AM, Renaud Gaujoux wrote:

> Alright.
> Maybe the symbol I chose was not appropriate. I tried ':' to be able to do 'a:name' with 'a' a S4 object.
> I get the following error:
> Error in genericForPrimitive(f) :
>  methods may not be defined for primitive function ":" in this version of R
> 
> Does there exist any symbol that would be suitable for the job?
> Thanks
> 
> -- 
> Renaud Gaujoux
> Computational Biology - University of Cape Town
> South Africa
> 
> 
> On 09/07/2010 14:29, Duncan Murdoch wrote:
>> On 09/07/2010 8:18 AM, Renaud Gaujoux wrote:
>>> Hi,
>>> 
>>> is there a way to define a method say '$$' that would behave like '$' and allow calls like 'a$$name'?
>> No, the parser handles a fixed syntax, and that expression is not legal.  You could do it with
>> 
>> a %$$% name
>> 
>> using the infix operator syntax.  (I think the description in the R Language Definition suggests this is not legal, since $$ is not a valid name, but it does currently work and that's unlikely to change.)
>> 
>> Duncan Murdoch



[Rd] Defining a method that behaves like '$'?
Marc Schwartz