如何使用 Roxygen2 添加类特定别名而不使用通用别名?
一个简单的例子是,我创建了 show
的扩展,它是 S4 基本方法。我不想通过在我的包中重新记录 show
来引起歧义分叉,并且我还想将我的扩展文档合并到 show
的文档中通过添加 show,myPkgSpClass-method
的别名来创建新类 myPkgSpClass
。
#' @export
#' @aliases show,myPkgSpClass-method
#' @rdname myPkgSpClass-class
setMethod("show", "myPkgSpClass", function(object){ show(NA) })
我遇到的问题是,这会在 roxygen2 的文档构建过程中导致严重警告,Rd 文件具有重复的别名“show”:
,因为 有多个类扩展show
在此包中,roxygen2 已自动将别名列表中的通用术语添加到所有相关的 *-class.Rd
文件中:
\alias{show}
\alias{show,myPkgSpClass-method}
但我认为我不想要通用术语任何实例中的别名,因为它将强制需要消除我的包中的 show
和基本 show
之间的歧义。除了 show
之外,此问题也适用于从其他包扩展的其他 S4 方法。
如果我将所有特定于类的方法标记到同一个 .Rd
文件,那么警告就会消失,但歧义仍然存在,因为 show
别名仍然会自动添加文档条目。如果我从 .Rd
文件中手动删除 \alias{show}
,那么问题似乎已解决,在 roxygen 或 R CMD 检查 pkgname
。那么如何让 Roxygen2 不添加通用别名呢?
其他背景:
这是从上一期导出/记录 S4 扩展到基本方法的具体问题: 是否需要导出基础R 包中的方法扩展?文档影响?
它比以下有关使用 Roxygen2 记录 S4 方法/类的问题更具体,但未涵盖:
A simple example is that I have created an extension to show
, which is a S4 base method. I don't want to cause a disambiguation fork by re-documenting show
in my package, and I also want to consolidate the documentation of my extension to show
in the documentation for the new class, myPkgSpClass
, by adding an alias for show,myPkgSpClass-method
.
#' @export
#' @aliases show,myPkgSpClass-method
#' @rdname myPkgSpClass-class
setMethod("show", "myPkgSpClass", function(object){ show(NA) })
The problem I'm having, is that this results in an serious warning during documentation-build by roxygen2, Rd files with duplicated alias 'show':
because there is more than one class extension to show
in this package, and roxygen2 has automatically added the generic term in the list of aliases to all the relevant *-class.Rd
files:
\alias{show}
\alias{show,myPkgSpClass-method}
But I think I don't want the generic alias in any of the instances, because it will force the need for disambiguation between show
in my package, and the base show
. This issue also applies to other S4 methods extended from other packages besides show
.
If I tag all class-specific methods to the same .Rd
file, then the warning goes away, but the ambiguity remains, because the show
alias still gets added automatically for that doc entry. If I manually remove \alias{show}
from the .Rd
file, then the problem seems solved, no warnings during roxygen or R CMD check pkgname
. So how do I get Roxygen2 to not-add the generic alias?
Other background:
This is a specific question building from a previous issue for exporting/documenting S4 extensions to base methods:
Is it necessary to export base method extensions in an R package? Documentation implications?
It is more specific than, and not covered by, the following questions regarding documenting S4 methods / classes using Roxygen2:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎已在 roxygen2_3.1.0 中修复:
生成 myPkgSpClass-class.Rd:
正如 Hadley 所说,您不再需要显式设置别名或 rd 名称,例如:
将生成 show-myPkgSpClass-method.Rd:
请注意在这种情况下,您必须设置描述。如果文档条目为空,它将不会生成文档页面。
Seems to be fixed in roxygen2_3.1.0:
produces the myPkgSpClass-class.Rd:
As Hadley stated, you do not need anymore to explicitly set the alias or the rd name, e.g.:
will generate show-myPkgSpClass-method.Rd:
Note that in that case you have to set the description. It will not generate a doc page if the documentation entry is empty.