How to document an R generic defined in an IF statement

Viewed 42

I have an R generic that's set in an IF statement:

if (is.null(getGeneric("isIdCurrent"))) {
  setGeneric("isIdCurrent", function(dbObj, ...) standardGeneric("isIdCurrent"))
}

If I don't document it, RStudio "Check" will complain about "Undocumented code objects". But if I try to document it (roxygen2 v7.1.1), e.g, like:

if (is.null(getGeneric("foo"))) {
#' @rdname myGnrc
  setGeneric("foo", function(dbObj, ...) standardGeneric("foo"))
}

RStudio "Clean and Rebuild" will complain about "@rdname Missing name".

If I remove the IF statement, then, of course, all my problems are solved:

#' @rdname myGnrc
setGeneric("foo", function(dbObj, ...) standardGeneric("foo"))

But I'm trying to maintain someone else code and I'm not sure if it's safe to remove the IF statement.

Any help will be highly appreciated!

1 Answers

After some reading and experimenting, I think it's safe to remove the IF statement.

Related