本文介绍了如何使用Roxygen2添加不带通用别名的特定于别名的别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的例子是我创建了一个扩展名为 show ,这是一个S4基本的方法。我不想通过在我的包中重新记录 show 来引起消歧叉,我也想将我的扩展名的文档整合到通过添加 show,myPkgSpClass-method myPkgSpClass 中显示 C $ C>。

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) })

我遇到的问题是,在文档创建过程中会导致严重的警告:roxygen2, Rd文件与重复的别名'show':因为这个包中有多个类扩展名为 show ,而roxygen2已经将别名列表中的通用术语添加到所有相关的 * -class.Rd 文件:

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}

但我想我不想要任何通用别名因为它会强制需要在我的包中的 show 和基础 show 之间消除歧义。此问题也适用于从 show 之外的其他软件包扩展的其他S4方法。

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.

如果我标记所有类特定方法到相同的 .Rd 文件,则警告消失,但是歧义仍然存在,因为显示别名自动添加该文档条目。如果我从 .Rd 文件手动删除 \alias {show} ,那么问题似乎解决了,没有警告在roxygen或 R CMD检查pkgname 。那么如何让Roxygen2不添加通用别名?

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?

其他背景:

这是一个以前的问题,从导出/记录S4扩展到基本方法的具体问题构建:

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?

它比以下关于使用Roxygen2记录S4方法/类的问题更具体,不涵盖:

It is more specific than, and not covered by, the following questions regarding documenting S4 methods / classes using Roxygen2:

推荐答案

似乎是固定的在roxygen2_3.1.0中:

Seems to be fixed in roxygen2_3.1.0:

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

生成myPkgSpClass-class.Rd:

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}
}

正如哈德利所说,你做不需要明确设置别名或rd名称,例如:

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) })

将生成show-myPkgSpClass-method.Rd:

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.

这篇关于如何使用Roxygen2添加不带通用别名的特定于别名的别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 04:55