This question was already asked in this stackoverflow question but the accepted answer (download the S4 branch from the author's repository) does not work for me and I think there might be a better way to achieve the same.
I have the following in my file generics.R
:
#' @rdname myfunction-methods
#' @name myfunction <- without this, roxygen2 complaints about missing name
#' @export
methods::setGeneric("myfunction",
function( arg1, arg2 ),
arg3, arg4 {
methods::standardGeneric("myfunction")
});
and then in my file mymethods.R
:
#' Something
#'
#' A brief description
#'
#' @param all params...
#' @return Something
#' @name myfunction <- without this, roxygen2 complaints on missing name
#' @include generics.R
#' @rdname myfunction-methods
#' @export
methods::setMethod( "myfunction",
methods::signature( arg1 = "formula", arg2 = "data.frame" ),
function( arg1, arg2, arg3, arg4 ) {
...whatever
}
)
With this, everything is fine except that the usage
section is not showing up. Could you please correct what is wrong in my documentation? More precisely:
Is it correct to write the documentation before setMethod or is it preferably before setGeneric ?
Why do I need the @name
in both files? Should it be different? Does it matter?
Do I need @export
in both files?
Would @alias
help at all?
Thank you very much in advance.
I can't answer all you questions but maybe the following helps:
roxygen2
does not recognize methods::setMethod
and methods::setGeneric
when the file is parsed. You have to avoid the use of ::
- not generally just here - by importing the methods-package into your namespace via #' @import methods
. Then you directly call setMethod
and setGeneric
without the reference to the package.When this does not solve your problem you can always define the usage entry manually and still use roxygen2 like this: #' @usage \S4method{myfunction}{formula,data.frame}(arg1, arg2)
.