如何导出S3方法以使其在名称空间中可用? [英] How to export S3 method so it is available in namespace?

查看:68
本文介绍了如何导出S3方法以使其在名称空间中可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包,对于S3方法,我使用

I am creating a package and for S3 methods I export them using

##' @method predict myclass
##' @export
predict.myclass <- function(object,...) { }

现在,当我加载程序包时,预测可以对类 myclass 的对象起作用,但是函数 predict.myclass 不会导出。在NAMESPACE中,我仅获得条目 S3method(predict,myclass)。因此,还有一种方法可以导出 predict.myclass ,以便用户在获得 predict.myclass 的代码时他(她)在控制台中编写 predict.myclass 吗?

Now when I load the package, then predict works on object of the class myclass, but function predict.myclass is not exported. In the NAMESPACE I only get the entry S3method(predict,myclass). So is there a way to export predict.myclass too, so that user will get the code of predict.myclass when he(she) writes predict.myclass in the console?

推荐答案

我的回答是不要那样做。用户可以方法(预测); getAnywhere(’predict.myclass’) mypackage ::: predict.myclass 。用户有一个学习曲线,但是掌握您的方法可以帮助用户浏览所有方法。不导出该方法的原因是,该方法不是要直接调用的,它会使搜索路径中出现不必要的符号(在提示符下键入的每个符号,例如 ls(),必须通过在 search()返回的所有环境中浏览对象来找到,并且像您这样的用户包位于搜索开始和名称解析之间这些常用功能)。

My answer is "don't do that". The user can methods(predict); getAnywhere('predict.myclass') or mypackage:::predict.myclass. There's a learning curve for the user, but mastering this with your method helps the user navigate all methods. Reasons not to export the method are that it isn't meant to be invoked directly, and it clutters the search path with unnecessary symbols (every symbol typed at the prompt, e.g., ls(), has to be found by looking through objects on all environments returned by search(), and user packages like yours stand between the start of the search and name resolution of these commonly used functions).

这篇关于如何导出S3方法以使其在名称空间中可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆