带有"缺失"参数的"["的S4文档

cde*_*man 7 r s4 roxygen2

这个问题与这个问题非常相似,但是当我尝试答案时,我会收到一个附加的"注意" R CMD check.虽然它只是一个NOTE我真的想要一个完全干净的检查.

* checking Rd line widths ... NOTE
Error: 8: no comma in argument list following \S4method
Execution halted
Run Code Online (Sandbox Code Playgroud)

如果我传递所有其他参数(i,j,drop)并记录所有参数但我不使用它,我可以摆脱这个.在我看来,如果在这种情况下不相关的情况下添加额外的文档将是一种浪费.

#' An S4 class that stores a list.
#' @export
setClass("testClass", 
                 representation(a="list"))

#' Extract parts of testClass.
#' @param x testClass
#'
setMethod("[", signature(x = "testClass"),
            function (x){
                print("void function")
            }
)
Run Code Online (Sandbox Code Playgroud)

Rd文件导致错误:

% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/test.R
\docType{methods}
\name{[,testClass-method}
\alias{[,testClass-method}
\title{Extract all elements}
\usage{
\S4method{[}{testClass}(x)
}
\arguments{
\item{x}{testClass}
}
\description{
Extract all elements
}
Run Code Online (Sandbox Code Playgroud)

如果我定义并记录所有参数,则以下Rd不会导致错误

% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/test.R
\docType{methods}
\name{[,testClass,missing,missing,missing-method}
\alias{[,testClass,missing,missing,missing-method}
\title{Extract all elements}
\usage{
\S4method{[}{testClass,missing,missing,missing}(x, i, j, drop)
}
\arguments{
\item{x}{testClass}

\item{i}{missing}

\item{j}{missing}

\item{drop}{missing}
}
\description{
Extract all elements
}
Run Code Online (Sandbox Code Playgroud)

Bro*_*ieG 4

您可以尝试尝试类似的方法:

setMethod("[", signature(x="testClass", i="missing", j="missing", drop="missing"), ...)
Run Code Online (Sandbox Code Playgroud)

尽管你甚至没有指定,这对我来说似乎很奇怪i。您也可以设置i"ANY".

此外,您可能需要将@param标签更新为:

#' @param x testClass
#' @param i missing
#' @param j missing
#' @param drop missing
Run Code Online (Sandbox Code Playgroud)

您可能不关心这些参数,但您正在使用定义它们的泛型([),因此您几乎有义务在您的方法中定义它们,因此也应该在文档中定义它们以突出显示您的特定方法不同于通用的。从?methods

方法定义需要具有与泛型函数相同的形式参数,因为出于效率和一致性的原因,方法分派机制不会重新匹配参数。