How to use/maintain my S4 class with same name as S4 class in another R package?
I'm writing a large R package that includes an S4 class named 'FeatureSet'. Unfortunately, this is also the name of a virtual S4 class in the widely used 'oligo' package. When I load my package first, and then oligo, and call
new("FeatureSet")
I get the error
Error in new("FeatureSet") :
trying to generate an object from a virtual class ("FeatureSet")
In the NAMESPACE file, I've tried including 'exportClasses' and 'exportClassPattern' to export this S4 definition, or all S4 definitions, from my package without luck. I've also included
exportMethods(coerce, initialize, show)
as I've defined methods for these generics in my package.
Is there a best-practice way to write R code to recognize only a specific S4 definition when multiple definitions with the same name are attached? I could, of course, give my class a different name, but there must be some way to make sure that my classes don't collide with those in some other package in the future. I've spent quite a while looking through the usual forums and documentation and was surprised to see that this question was not answered anywhere. Thanks in advance!
答案 0 :(得分:1)
我认为最佳做法是选择一个不同的,更具描述性的名称。拥有两个同名但结构不同的对象本质上是令人困惑的。
您可以通过
构建“您的”课程的实例new(getClass("FeatureSet", where=getNamespace("YourPackage")))`
可能包含在一个简单的'构造函数'函数中。
虽然原则上方法包'知道'你的类的实例和来自另一个包的同名的类之间的区别,但你几乎肯定会遇到会使你和你的用户感到沮丧的实现错误。 / p>