What is the correct way to import an S3 method without importing the whole package

雨燕双飞 提交于 2020-01-13 05:30:10

问题


I would like to use one function from a package called myPackage called as.data.frame.mywhateverS3class

When I look at the package NAMESPACE it looks as follows: S3method(as.data.frame, mywhateverS3class) I would like to use this function inside another package. What I would normally do is specify this in roxygen2 as @import myPackage such that this generates import(myPackage) inside the other package. That works.

But in this case I would like not to import the whole package but only the S3 method. When I specify importFrom(myPackage, as.data.frame), or importFrom(myPackage, as.data.frame.mywhateverS3class) this fails as as.data.frame is not exported in myPackage and as.data.frame.mywhateverS3class is hidden when I type methods(as.data.frame)

Do I really need to import the whole package NAMESPACE for this? I'm looking at http://cran.r-project.org/doc/manuals/R-exts.html and can't seem to find how to restrict the import to just the S3method without importing the whole NAMESPACE. Is there a way to do this?

来源:https://stackoverflow.com/questions/23112762/what-is-the-correct-way-to-import-an-s3-method-without-importing-the-whole-packa

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!