Re: [Rd] Defining a method that behaves like '$'?

From: Renaud Gaujoux <renaud_at_mancala.cbio.uct.ac.za>
Date: Fri, 09 Jul 2010 15:10:08 +0200

I do not want to access the slot itself but its content: a:toto would be a_at_slot1[['toto']].
The thing is that I would like to have two different methods: '$' (that I already have) and another one to define, ideally that behaves like '$'. So in brief:
- a:toto would be for a_at_slot1[['toto']]
- a$tata would be for a_at_slot2[['tata']]

But apparently it might not be possible.

-- 
Renaud Gaujoux
Computational Biology - University of Cape Town
South Africa


On 09/07/2010 14:58, Marc Schwartz wrote:

> 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
>>>
>
### UNIVERSITY OF CAPE TOWN This e-mail is subject to the UCT ICT policies and e-mail disclaimer published on our website at http://www.uct.ac.za/about/policies/emaildisclaimer/ or obtainable from +27 21 650 4500. This e-mail is intended only for the person(s) to whom it is addressed. If the e-mail has reached you in error, please notify the author. If you are not the intended recipient of the e-mail you may not use, disclose, copy, redirect or print the content. If this e-mail is not related to the business of UCT it is sent by the sender in the sender's individual capacity. ### ______________________________________________ R-devel_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri 09 Jul 2010 - 13:11:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 10 Jul 2010 - 15:40:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive