In my R package, I implemented the [
(indexing) operator for my class:
#' Some title
#' @export
setMethod("[", list(x="MyClass"), function(x, i, j, ...) {
# Some code
})
Now, in the package documentation I want to link to the manual entry for this method. I try the normal way, using methodName,className-method
:
#' [[,MyClass-method]
But that just puts a left bracket outside of the \link
command in the .Rd
file:
[\link{,MyClass-method}
If I try to quote it in some way, I get other issues: I have tried backtick, single and double quotes, and finally doubling the bracket [[
but none of these seem to produce a link that actually works in the final PDF.
How can I cross reference a [
method using Roxygen?
From the "rd-formatting" vignette in roxygen2
(which you can see using vignette("rd-formatting", package = "roxygen2")
):
Links to operators or objects that contain special characters do not currently work. So to link to (e.g.) the
%>%
operator in themagrittr
package, instead of[magrittr::%>%]
, you will need to use the Rd notation:\code{\link[magrittr]{\%>\%}}
.
This works for documenting [
, plus other operators, including the "assign" operators/functions that use the "assign" operator, <-
. For example,
\code{\link[myPackage]{[}}
\code{\link[myPackage]{[[}}
\code{\link[myPackage]{$}}
\code{\link[myPackage]{[<-}}
\code{\link[myPackage]{[[<-}}
\code{\link[myPackage]{[levels<-}}
all work. If you want to link to the operator of another package, replace myPackage
with otherPackage
.
On the same note, the roxygen2
method of making links like, [levels<-]
or [$]
will not work for these kinds of links, or if they do, throw notes/warnings when using devtools::check()
nonetheless.