[Rd] Define S4 methods for 'plot'

cgenolin cgenolin at u-paris10.fr
Wed Nov 9 19:08:56 CET 2011


Hi the list
I am creating a package and I have a problem to define a S4 method for plot.
I define a class 'A' and a class 'B'. I want to define a function plot for
signature c(A,missing) and another method plot for signature c(A,B). My code
is the following :

In /package/R/ directory:
--- main.R ---
setGeneric("plot",function(x,y,...){standardGeneric("plot")})
Aplot <- function(x,paramTraj=3){. . . .}
setMethod("plot",signature=c(x="A",y="missing"),Aplot)

ABplot <- function(x,y,paramTraj=5){. . . .}
setMethod("plot",signature=c(x="A",y="B"),ABplot)
---------------

In the root directory /package/
--- NAMESPACE ---
exportMethods("plot",. . . .)
exportClasses("A","B")
------
When I run the code (source("main.r")), every thinks works fine, either plot
on object of class 'A', on 'A,B' or on numeric plot(3). 

The R CMD check bug on an example using plot(3).
The R CMD build works just fine. But if I try to install the package from
the builded file, I get the message:
The following object(s) are masked from 'package:graphics':
    plot.

And then, I cannot use the classical function plot: plot on object 'A'
works, but plot(1) does not.

I try, reading some recent post on r-devel to remove the line 'setGeneric'
but it does not works (which does not surprise me since getGeneric("plot")
gives a NULL results).
 
Any idea of what goes wrong?

Christophe


--
View this message in context: http://r.789695.n4.nabble.com/Define-S4-methods-for-plot-tp4020750p4020750.html
Sent from the R devel mailing list archive at Nabble.com.



More information about the R-devel mailing list