[Rd] methods/namespaces/possible bug
Duncan Murdoch
murdoch at stats.uwo.ca
Tue Jul 15 21:00:57 CEST 2008
On 7/15/2008 2:11 PM, Kasper Daniel Hansen wrote:
> Using
>
> > methods("plot")
> [1] plot.Date* plot.HoltWinters* plot.POSIXct*
> [4] plot.POSIXlt* plot.TukeyHSD plot.acf*
> [7] plot.data.frame* plot.decomposed.ts* plot.default
> [10] plot.dendrogram* plot.density plot.ecdf
> [13] plot.factor* plot.formula* plot.hclust*
> [16] plot.histogram* plot.isoreg* plot.lm
> [19] plot.medpolish* plot.mlm plot.ppr*
> [22] plot.prcomp* plot.princomp* plot.profile.nls*
> [25] plot.spec plot.spec.coherency plot.spec.phase
> [28] plot.stepfun plot.stl* plot.table*
> [31] plot.ts plot.tskernel*
>
> Non-visible functions are asterisked
>
> I don't see plot.function listed. As I read the man page for methods I
> would say that the search is just looking for functions with the right
> type of name.
In a package with a NAMESPACE (like the graphics package, where
plot.function lives), a function needs to be declared to be an S3method
to show up in this list. plot.function is not declared as an S3 method.
I don't know the reason for this, but I assume it's intentional: take a
look at the plot() generic: it has special case code to handle functions.
So if this is a bug, I think it's a documentation bug in the
?plot.function man page, where plot.function should be documented to act
a lot like an S3 method, but not identically like one: notice the
special handling of the y axis label.
> If I define a plot.function in my global workspace, methods("plot")
> picks it up
>
> > plot.function = function() {print("blah")}
> > methods("plot")
> [1] plot.Date* plot.HoltWinters* plot.POSIXct*
> [4] plot.POSIXlt* plot.TukeyHSD plot.acf*
> [7] plot.data.frame* plot.decomposed.ts* plot.default
> [10] plot.dendrogram* plot.density plot.ecdf
> [13] plot.factor* plot.formula* plot.function
> [16] plot.hclust* plot.histogram* plot.isoreg*
> [19] plot.lm plot.medpolish* plot.mlm
> [22] plot.ppr* plot.prcomp* plot.princomp*
> [25] plot.profile.nls* plot.spec plot.spec.coherency
> [28] plot.spec.phase plot.stepfun plot.stl*
> [31] plot.table* plot.ts plot.tskernel*
Functions declared in the global workspace are handled by patterns on
the name, since you can't declare things there: there's no NAMESPACE file.
> Non-visible functions are asterisked
>
> Based on this, I think that methods("plot") should return
> plot.function, so I am almost ready to take the bug word in my mouth.
>
> When I debug the methods function it gets to the line
> S3reg <- ls(get(".__S3MethodsTable__.", envir = defenv), pattern =
> name)
> where it searches the .__S3MethodsTable__. object. Consulting the help
> page it seems that this object is part of the namespace functionality.
>
> My guess is that something goes wrong because function is a reserved
> word?
I don't think so.
Duncan Murdoch
>
> Kasper
>
> This has been tested under R-2.7.1 on Mac OS X and under a not too
> recent version of R-devel under x86_64. My sessionInfo for the Mac
> version is
>
> > sessionInfo()
> R version 2.7.1 (2008-06-23)
> i386-apple-darwin8.10.1
>
> locale:
> en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> loaded via a namespace (and not attached):
> [1] tools_2.7.1
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
More information about the R-devel
mailing list