R CMD check warning: Functions/methods with usage in documentation object … but not in code

时光怂恿深爱的人放手 提交于 2019-12-03 11:17:05

问题


I am writing a package but one persistent R CMD check warning prevents me from finishing the package and posting it to CRAN. I use roxygen2 for inline documentation, although that possibly isn't the root cause of the error.

If you know what to do to remove this warning, I can quite possibly figure out a way of doing it using roxygen2.

How can I remove the warning Functions/methods with usage in documentation object ... but not in code from my package checks?


The R CMD check warning:

* checking for code/documentation mismatches ... WARNING
Functions/methods with usage in documentation object 'names<-' but not in code:
  names<-

The function and roxygen documentation:

#' Updates names and variable.labels attribute of surveydata.
#' 
#' @name names<-
#' @rdname names
#' @aliases names<- names<-.surveydata
#' @param x surveydata object
#' @param value New names
#' @method names<- surveydata
#' @usage names(x) <- value
"names<-.surveydata" <- function(x, value){
    invisible(NULL)
}

The resulting .rd documentation file:

\name{names<-}
\alias{names<-}
\alias{names<-.surveydata}
\title{Updates names and variable.labels attribute of surveydata.}
\usage{
  names(x) <- value
}
\arguments{
  \item{x}{surveydata object}

  \item{value}{New names}
}
\description{
  Updates names and variable.labels attribute of
  surveydata.
}

I have cross-checked my documentation with the documentation for names<- in base R, and it seems identical:

\title{  The Names of an Object}
\name{names}
\alias{names}
\alias{names.default}
\alias{names<-}
\alias{names<-.default}
\keyword{attribute}
\description{Functions to get or set the names of an object.}

Related question (but I have already implemented the suggestion and still no luck):

  • How to properly document a S3 method of a generic from a different package, using Roxygen?

Where am I going wrong? How can I remove this warning from the package checks?


回答1:


The \usage section in the Rd file needs to include the following:

\method{names}{surveydata}(x) <- value

If this is not automatically inserted by the @method line (I presume that will only add \method{names}{surveydata}(x)?) then you need an explicit @usage section that includes the above. Something like

#' @usage \\method{names}{surveydata}(x) <- value

I would also change the @name and @alias sections to refer to the method explicitly not the generic as that will clash with the Rd file in R::base.

Essentially, the warning is coming from the fact that your package doesn't contains a function "names<-" yet you are using this in \usage{}.




回答2:


In case it helps anyone, this error can also arise from an abandoned Rd file for which a function or data object no longer exists.



来源:https://stackoverflow.com/questions/11285496/r-cmd-check-warning-functions-methods-with-usage-in-documentation-object-bu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!