'R package documentation: "Undocumented arguments in documentation object" for a function with no arguments
I receive the following warning when trying to check my package: Undocumented arguments in documentation object '%ni%' '...' 'NA'. The function (is it even a function? or is it just an operator?) doesn't take any arguments, but it appears that R is somehow identifying arguments (... and NA) that are not documented.
Here is the document that I use with roxygen2 to create the package documentation:
#' @title
#' NOTIN Operator.
#'
#' @description
#' NOTIN operator.
#'
#' @details
#' Determine whether values in one vector are not in another vector.
#'
#' @return Vector of \code{TRUE} and \code{FALSE}, indicating whether values in
#' one vector are not in another vector.
#'
#' @family operators
#'
#' @export
#'
#' @examples
#' # Prepare Data
#' v1 <- c("Sally","Tom","Barry","Alice")
#' listToCheckAgainst <- c("Tom","Alice")
#'
#' v1 %ni% listToCheckAgainst
#' v1[v1 %ni% listToCheckAgainst]
#'
#' @seealso
#' \url{https://www.r-bloggers.com/2018/07/the-notin-operator/}
`%ni%` <- Negate(`%in%`)
Here is the relevant output I receive when checking the package:
W checking for code/documentation mismatches (1.9s)
Codoc mismatches from documentation object '%ni%':
%ni%
Code: function(...)
Docs: function(..., NA)
Argument names in docs not in code:
NA
W checking Rd \usage sections (3.7s)
Undocumented arguments in documentation object '%ni%'
'...' 'NA'
Functions with \usage entries need to have the appropriate \alias
entries, and all their arguments documented.
The \usage entries must correspond to syntactically valid R code.
See chapter 'Writing R documentation files' in the 'Writing R
Extensions' manual.
How can I get rid of the warning?
Solution 1:[1]
You can see the arguments to %in% and your %ni% operator using
args(`%in%`)
#> function (x, table)
#> NULL
`%ni%` <- Negate(`%in%`)
args(`%ni%`)
#> function (...)
#> NULL
Created on 2022-03-01 by the reprex package (v2.0.1.9000)
So it looks like Negate() replaced the %in% arguments with ..., and Roxygen messed up the help page generation. I think you will need to write the Rd file manually, or use an explicit definition of %ni%, or do something else to tell Roxygen how to get the usage right.
EDITED to add:
Another choice is to use a better Negate function that keeps the arguments, for example
Negate2 <- function (f)
{
f <- match.fun(f)
args <- names(formals(f))
result <- function() !do.call(f, sapply(args, as.name))
formals(result) <- formals(f)
result
}
`%ni%` <- Negate2(`%in%`)
args(`%ni%`)
#> function (x, table)
#> NULL
Created on 2022-03-01 by the reprex package (v2.0.1.9000)
This would require you to document the x and table arguments, but shouldn't cause problems in Roxygen. I think it should evaluate properly, but I haven't done much testing.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
