Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S4 documentation of "[" with 'missing' arguments

Tags:

r

s4

roxygen2

This question is very similar to this question but when I try the answer I receive an addition 'NOTE' following R CMD check. Although it is just a NOTE I would really like to have a completely clean check.

* checking Rd line widths ... NOTE
Error: 8: no comma in argument list following \S4method
Execution halted

I can get rid of this if I pass all the other parameters (i,j,drop) and document all of them but I don't use them. It seems to me that it would be a waste to just add in extra documentation when it isn't relevant in this case.

#' 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")
            }
)

The Rd file resulting in the error:

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

The following Rd results in no error if I define and document all the arguments

% 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
}
like image 545
cdeterman Avatar asked Jul 07 '15 14:07

cdeterman


1 Answers

You can try try something like:

setMethod("[", signature(x="testClass", i="missing", j="missing", drop="missing"), ...)

though it seems pretty weird to me that you're not even specifying i. You could also set i to "ANY".

Also, you will likely have to update your @param tags to something like:

#' @param x testClass
#' @param i missing
#' @param j missing
#' @param drop missing

You may not care about those parameters, but you are using a generic that defines them ([) so you are pretty much obligated to define them in your method and as such should also define them in the docs to highlight your particular method is different from the generic. From ?methods:

Method definitions are required to have the same formal arguments as the generic function, since the method dispatch mechanism does not rematch arguments, for reasons of both efficiency and consistency.

like image 79
BrodieG Avatar answered Sep 28 '22 13:09

BrodieG