Roxygen2 - 如何正确记录 S3 方法
我已经阅读了 Roxygen2 PDF 和这个网站,但我迷路了关于 @method @S3method @export 之间的区别以及如何使用它们来正确记录 S3 方法。我编写了以下示例进行讨论:
- 我如何正确记录这些?
- 如何模拟 ?print 和其他通用函数的文档,以显示所有特定于类的用例implimentations(即 ?print 显示“factor”、“table”、“function”用法的方式)
- 来自 wiki 页面:“所有导出的方法都需要 @S3method 标记。它与 @ 的格式相同该方法导出。方法,而不是函数 - 即 generic(myobject) 可以工作,但 generic.mymethod(myobject) 不会。”
我无法解释这一点。这似乎是说,如果标签指定不正确,函数/方法调用将无法正常工作?具体会破坏什么?
MyHappyFunction = function( x , ... )
{
UseMethod( "MyHappyFunction" )
}
MyHappyFunction.lm = function( x , ... )
{
# do some magic
}
I've read the Roxygen2 PDF and this site, and I'm lost on the difference between @method @S3method @export and how to use these to properly document S3 methods. I worked up the follow example for discussion:
- How would I properly document these?
- How do I emulate documentation of ?print and other generic functions that show the use cases for all class-specific implimentations (i.e. the way ?print shows usage for 'factor', 'table','function')
- From the wiki page: "All exported methods need the @S3method tag. It has the same format as @method. This exports the method, not the function - i.e. generic(myobject) will work, but generic.mymethod(myobject) will not."
I can't interpret this. This seems to say that function/method calls won't work properly if the tags are improperly specified? What specifically will break?
MyHappyFunction = function( x , ... )
{
UseMethod( "MyHappyFunction" )
}
MyHappyFunction.lm = function( x , ... )
{
# do some magic
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 roxygen2 >3.0.0 开始,您只需要
@export
:但由于您实际上并未记录这些方法,因此以下是
充足的:
As of roxygen2 >3.0.0, you only need
@export
:But since you're not actually documenting the methods, the following is
sufficient:
@method
标记在 Rd 文件的 \usage 字段中生成 \method 条目。@S3method
标记在 NAMESPACE 文件中生成 S3method() 条目。@export
标记在 NAMESPACE 文件中生成 export() 条目。这是我的示例:
我猜这意味着“你不写
@S3method generic mymethod myobject
”。The
@method
tag generates \method entries in the \usage field in Rd files.The
@S3method
tag generates S3method() entries in the NAMESPACE file.The
@export
tag generates export() entries in the NAMESPACE file.Here is my example:
I guess that it means "you do not write
@S3method generic mymethod myobject
."