[Rd] S4 generic masking S3 generic when using namespace

Sklyar, Oleg (London) osklyar at maninvestments.com
Tue Mar 10 11:16:35 CET 2009


Try using setGeneric("predict") without further arguments, this should
work as it will take the existing 'predict' definition and convert it
into S4 generic. This works nicely for me for all plot, print etc
methods

* R   
*** R 2.9.0 (svn -r 47821) [/share/research/R-devel/20090203/lib64/R]
***
> setGeneric("predict")
[1] "predict"
> predict
standardGeneric for "predict" defined from package "stats"

function (object, ...) 
standardGeneric("predict")
<environment: 0xe24b080>
Methods may be defined for arguments: object
Use  showMethods("predict")  for currently available ones.

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
osklyar at maninvestments.com 

> -----Original Message-----
> From: r-devel-bounces at r-project.org 
> [mailto:r-devel-bounces at r-project.org] On Behalf Of Gad Abraham
> Sent: 10 March 2009 10:02
> To: R-devel at r-project.org
> Subject: [Rd] S4 generic masking S3 generic when using namespace
> 
> Hi,
> 
> I have two example packages, test1 and test2, where the only code in 
> them is:
> 
> setGeneric("predict", function(object, ...) 
> standardGeneric("predict"))
> 
> (get them from http://www.cs.mu.oz.au/~gabraham/test1.tar and 
> http://www.cs.mu.oz.au/~gabraham/test2.tar)
> 
> The difference between them is that first does not have a 
> namespace, and 
> loads fine. The second has a namespace but generates a warning:
>  > library(test2)
> 
> Attaching package: 'test2'
> 
> 
> 	The following object(s) are masked from package:stats :
> 
> 	 predict
> 
> 
> 
> Is this an intended behaviour? If I ignore this masking warning, do I 
> risk unintended consequences later down the track?
> 
> Thanks,
> Gad
> 
> 
> 
>  > sessionInfo()
> R version 2.8.1 (2008-12-22)
> i386-apple-darwin8.11.1
> 
> locale:
> en_AU.UTF-8/en_AU.UTF-8/C/C/en_AU.UTF-8/en_AU.UTF-8
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> 
> other attached packages:
> [1] test2_0.1
> 
> 
> -- 
> Gad Abraham
> MEng Student, Dept. CSSE and NICTA
> The University of Melbourne
> Parkville 3010, Victoria, Australia
> email: gabraham at csse.unimelb.edu.au
> web: http://www.csse.unimelb.edu.au/~gabraham
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 

**********************************************************************
Please consider the environment before printing this email or its attachments.
The contents of this email are for the named addressees ...{{dropped:19}}



More information about the R-devel mailing list