Re: [Rd] format: different S4 behavior in a package

From: Uwe Ligges <ligges_at_statistik.tu-dortmund.de>
Date: Wed, 23 Jun 2010 09:33:39 +0200

There is not a single definition of
formatMe()
in your message, therefore nothing works for me, not even the very first version...

Best,
Uwe Ligges

On 23.06.2010 09:16, Daniel Murphy wrote:
> R-Devel-ers:
>
> I have an S4 method that simply formats an object:
>
> setGeneric("formatMe", function(x) standardGeneric("formatMe"))
> setMethod("formatMe", "ANY", function(x) format(x))
>
> If I issue the above in an R session, then define an S4 class with its own
> format method, I get the desired result:
>
>> setClass("A",contains="numeric")
> [1] "A"
>> setMethod("format","A", function(x, ...) "Hey Jude")
> Creating a new generic function for "format" in ".GlobalEnv"
> [1] "format"
>> a<-new("A",1968)
>> formatMe(a)
> [1] "Hey Jude"
>
>
> However, if I put the two "formatMe" definitions into a package ("Test"), I
> do not get the desired result.
> <start new R session>
>
>> library(Test)
>> setClass("A",contains="numeric")
> [1] "A"
>> setMethod("format","A", function(x, ...) "Hey Jude")
> Creating a new generic function for "format" in ".GlobalEnv"
> [1] "format"
>> a<-new("A",1968)
>> formatMe(a)
> [1] "1968"
>
>
> The "disconnect" does not occur, however, if the S4 format method is an S3
> incarnation:
>
>> setClass("B",contains="numeric",S3methods=TRUE)
> [1] "B"
>> format.B<- function(x, ...) "Don't make it bad"
>> b<-new("B",1968)
>> formatMe(b)
> [1] "Don't make it bad"
>
> Could the problem be in Test's NAMESPACE file? There is only one line:
> exportMethods(formatMe)
>
> Here is Test's DESCRIPTION file:
> Package: Test
> Type: Package
> Title: Testing format
> Version: 1.0
> Date: 2010-06-22
> Author: Dan Murphy
> Maintainer: Dan Murphy<snipped>
> Depends: methods
> Description: Does format in a package work with S4 format method?
> License: GPL (>= 2)
> LazyLoad: yes
>
> (I would send the Help file, but I don't think that is the problem.)
>
> I am using version 2.11.1 on a Windows Vista machine.
>
> Any guidance would be appreciated. Thank you
>
> Dan Murphy
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 23 Jun 2010 - 07:42:15 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 Wed 23 Jun 2010 - 09:01:15 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