From romain at r-enthusiasts.com  Sat May 29 21:37:07 2010
From: romain at r-enthusiasts.com (Romain Francois)
Date: Sat, 29 May 2010 21:37:07 +0200
Subject: [Rd] S4 dispatch for .DollarNames (utils)
In-Reply-To: <AANLkTimkEzQ5GLpnWHJr1EuBcNBmwod81UzBFs0fXusk@mail.gmail.com>
References: <4C00F8C2.4060508@r-enthusiasts.com>
	<AANLkTimkEzQ5GLpnWHJr1EuBcNBmwod81UzBFs0fXusk@mail.gmail.com>
Message-ID: <4C016CE3.8050403@r-enthusiasts.com>

Le 29/05/10 20:23, Deepayan Sarkar a ?crit :
> On Sat, May 29, 2010 at 4:21 AM, Romain Francois
> <romain at r-enthusiasts.com>  wrote:
>> Hello,
>>
>> I'm trying to make .DollarNames generic and implement a method for it in a
>> package. .DollarNames is the function that is now called to get completion
>> possibilities.
>>
>> My R code looks like this:
>>
>> setGeneric( ".DollarNames" )
>>
>> setClass("track",
>>          representation(x="numeric", y="numeric"))
>> ## A class extending the previous, adding one more slot
>> setClass("trackCurve",
>>     representation(smooth = "numeric"),
>>     contains = "track")
>>
>> setMethod( ".DollarNames", signature( x = "track", pattern = "character" ),
>> function(x, pattern){
>>         grep( pattern, c("foo", "bar"), value = TRUE )
>> } )
>>
>>
>> and the NAMESPACE :
>>
>> import( utils )
>> exportMethods( .DollarNames )
>> exportClasses( track, trackCurve )
>>
>>
>> When I load the package, I can call .DollarNames explicitely :
>>
>>> require( foo )
>>> x<- new( "trackCurve", x = 1:10, y = 1:10, smooth = 1:10 )
>>> .DollarNames( x, "f" )
>> [1] "foo"
>>
>> but completion does not work :
>>
>>> x$f<TAB>
>> x$
>
> I guess because
>
>> utils:::.DollarNames(x, "f")
> character(0)

yes. hence the hack I used when replying which is probably not a good 
idea, specially if two packages want it.

> so the S4 generic is not being seen within the utils namespace. I
> don't know what the right fix is...
>
> -Deepayan

Perhaps something like the attached ?

defining a generic in methods and use this one when methods dispatch is on.


>> What do I miss ?
>>
>> I've uploaded foo here : http://addictedtor.free.fr/misc/rcpp/foo_1.0.tar.gz
>>
>> Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/99bz5D : highlight 0.1-9
|- http://bit.ly/9CQ66r : RMetrics 2010
`- http://bit.ly/bklUXt : RcppArmadillo 0.2.1


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dollarnames.diff
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20100529/beae8e39/attachment.pl>


[Rd] S4 dispatch for .DollarNames (utils)
Romain Francois