S4 dispatch and S3 "connection" objects

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

S4 dispatch and S3 "connection" objects

Romain Francois
Hello,

I'm trying to get S4 dispatch on S3 "connection" objects.

So I do :

setOldClass( "connection" )

and then :

setGeneric( "bling", function(object) standardGeneric( "bling" ) )
setMethod( "bling", "connection", function(object) cat( "gotcha ",
as.integer(object), "\n" ) )

but I get :

f <- file( "blabla", open = "rb" )

 > bling( f )
Error in function (classes, fdef, mtable)  :
   unable to find an inherited method for function "bling", for
signature "file"
 > class( f )
[1] "file"       "connection"


Am I supposed to do :

setOldClass( c("file", "connection" ) )
setOldClass( c("url", "connection" ) )

and so on for each potential S3 class, or is there another way.

Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/HlX9 : new package : bibtex
|- http://tr.im/Gq7i : ohloh
`- http://tr.im/FtUu : new package : highlight

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: S4 dispatch and S3 "connection" objects

Michael Lawrence-3
On Mon, Dec 14, 2009 at 11:36 PM, Romain Francois <
[hidden email]> wrote:

> Hello,
>
> I'm trying to get S4 dispatch on S3 "connection" objects.
>
> So I do :
>
> setOldClass( "connection" )
>
> and then :
>
> setGeneric( "bling", function(object) standardGeneric( "bling" ) )
> setMethod( "bling", "connection", function(object) cat( "gotcha ",
> as.integer(object), "\n" ) )
>
> but I get :
>
> f <- file( "blabla", open = "rb" )
>
> > bling( f )
> Error in function (classes, fdef, mtable)  :
>  unable to find an inherited method for function "bling", for signature
> "file"
> > class( f )
> [1] "file"       "connection"
>
>
> Am I supposed to do :
>
> setOldClass( c("file", "connection" ) )
> setOldClass( c("url", "connection" ) )
>
> and so on for each potential S3 class, or is there another way.
>
>
That's the way I've always done it.

Michael


> Romain
>
> --
> Romain Francois
> Professional R Enthusiast
> +33(0) 6 28 91 30 30
> http://romainfrancois.blog.free.fr
> |- http://tr.im/HlX9 : new package : bibtex
> |- http://tr.im/Gq7i : ohloh
> `- http://tr.im/FtUu : new package : highlight
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: S4 dispatch and S3 "connection" objects

John Chambers-2
We should probably incorporate this information in the pre-defined S4
versions of the classes, since these are basic S3 classes. Anybody see a
down side?

Meanwhile, your approach is a reasonable workaround.

John

Michael Lawrence wrote:

> On Mon, Dec 14, 2009 at 11:36 PM, Romain Francois <
> [hidden email]> wrote:
>
>  
>> Hello,
>>
>> I'm trying to get S4 dispatch on S3 "connection" objects.
>>
>> So I do :
>>
>> setOldClass( "connection" )
>>
>> and then :
>>
>> setGeneric( "bling", function(object) standardGeneric( "bling" ) )
>> setMethod( "bling", "connection", function(object) cat( "gotcha ",
>> as.integer(object), "\n" ) )
>>
>> but I get :
>>
>> f <- file( "blabla", open = "rb" )
>>
>>    
>>> bling( f )
>>>      
>> Error in function (classes, fdef, mtable)  :
>>  unable to find an inherited method for function "bling", for signature
>> "file"
>>    
>>> class( f )
>>>      
>> [1] "file"       "connection"
>>
>>
>> Am I supposed to do :
>>
>> setOldClass( c("file", "connection" ) )
>> setOldClass( c("url", "connection" ) )
>>
>> and so on for each potential S3 class, or is there another way.
>>
>>
>>    
> That's the way I've always done it.
>
> Michael
>
>
>  
>> Romain
>>
>> --
>> Romain Francois
>> Professional R Enthusiast
>> +33(0) 6 28 91 30 30
>> http://romainfrancois.blog.free.fr
>> |- http://tr.im/HlX9 : new package : bibtex
>> |- http://tr.im/Gq7i : ohloh
>> `- http://tr.im/FtUu : new package : highlight
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>    
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>  

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: S4 dispatch and S3 "connection" objects

Romain Francois
On 12/16/2009 12:52 AM, John Chambers wrote:
> We should probably incorporate this information in the pre-defined S4
> versions of the classes, since these are basic S3 classes.

That'd be good.

> Anybody see a
> down side?
>
> Meanwhile, your approach is a reasonable workaround.
>
> John
>
> Michael Lawrence wrote:
>> On Mon, Dec 14, 2009 at 11:36 PM, Romain Francois<
>> [hidden email]>  wrote:
>>
>>
>>> Hello,
>>>
>>> I'm trying to get S4 dispatch on S3 "connection" objects.
>>>
>>> So I do :
>>>
>>> setOldClass( "connection" )
>>>
>>> and then :
>>>
>>> setGeneric( "bling", function(object) standardGeneric( "bling" ) )
>>> setMethod( "bling", "connection", function(object) cat( "gotcha ",
>>> as.integer(object), "\n" ) )
>>>
>>> but I get :
>>>
>>> f<- file( "blabla", open = "rb" )
>>>
>>>
>>>> bling( f )
>>>>
>>> Error in function (classes, fdef, mtable)  :
>>>   unable to find an inherited method for function "bling", for signature
>>> "file"
>>>
>>>> class( f )
>>>>
>>> [1] "file"       "connection"
>>>
>>>
>>> Am I supposed to do :
>>>
>>> setOldClass( c("file", "connection" ) )
>>> setOldClass( c("url", "connection" ) )
>>>
>>> and so on for each potential S3 class, or is there another way.
>>>
>>>
>>>
>> That's the way I've always done it.
>>
>> Michael
>>
>>
>>
>>> Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/HlX9 : new package : bibtex
|- http://tr.im/Gq7i : ohloh
`- http://tr.im/FtUu : new package : highlight

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel