如何使用 Roxygen2 添加类特定别名而不使用通用别名?

发布于 2024-12-28 07:01:40 字数 1549 浏览 7 评论 0原文

一个简单的例子是,我创建了 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 方法/类的问题更具体,但未涵盖:

如何使用 roxygen2 正确记录 S4 方法

如何使用 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:

How to properly document S4 methods using roxygen2

How to properly document S4 class slots using Roxygen2?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉目亦如画i 2025-01-04 07:01:40

似乎已在 roxygen2_3.1.0 中修复:

#' @export
#' @aliases show,myPkgSpClass-method
#' @rdname myPkgSpClass-class
setMethod("show", "myPkgSpClass", function(object){ show(NA) })

生成 myPkgSpClass-class.Rd:

\docType{methods}
\name{show,myPkgSpClass-method}
\alias{show,myPkgSpClass-method}
\usage{
\S4method{show}{myPkgSpClass}(object)
}
\arguments{
  \item{object}{Any R object}
}

正如 Hadley 所说,您不再需要显式设置别名或 rd 名称,例如:

#' my title
#' @export
setMethod("show", "myPkgSpClass", function(object){ show(NA) })

将生成 show-myPkgSpClass-method.Rd:

\docType{methods}
\name{show,myPkgSpClass-method}
\alias{show,myPkgSpClass-method}
\title{my title}
\usage{
\S4method{show}{myPkgSpClass}(object)
}
\arguments{
  \item{object}{Any R object}
}
\description{
my title
}

请注意在这种情况下,您必须设置描述。如果文档条目为空,它将不会生成文档页面。

Seems to be fixed in roxygen2_3.1.0:

#' @export
#' @aliases show,myPkgSpClass-method
#' @rdname myPkgSpClass-class
setMethod("show", "myPkgSpClass", function(object){ show(NA) })

produces the myPkgSpClass-class.Rd:

\docType{methods}
\name{show,myPkgSpClass-method}
\alias{show,myPkgSpClass-method}
\usage{
\S4method{show}{myPkgSpClass}(object)
}
\arguments{
  \item{object}{Any R object}
}

As Hadley stated, you do not need anymore to explicitly set the alias or the rd name, e.g.:

#' my title
#' @export
setMethod("show", "myPkgSpClass", function(object){ show(NA) })

will generate show-myPkgSpClass-method.Rd:

\docType{methods}
\name{show,myPkgSpClass-method}
\alias{show,myPkgSpClass-method}
\title{my title}
\usage{
\S4method{show}{myPkgSpClass}(object)
}
\arguments{
  \item{object}{Any R object}
}
\description{
my title
}

Note that in that case you have to set the description. It will not generate a doc page if the documentation entry is empty.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文