Question

I'm writing a package with an S4 class, and I've written methods for as.POSIXct and as.POSIXlt for the class. I've written the documentation and everything looks fine, except that I would like to reference the as.POSIXct method in the documentation for as.POSIXlt, and vice versa. I tried \S4method{coerce}{abc, POSIXct}(from, to), (where 'abc' is the S4 class), but that is only supposed to be put in the \usage section, which isn't where I want it. Is there a way to do this? It seems odd to me that it would not be allowed.

I realize that it is possible to combine these .rd files and avoid this issue, but I'm trying to learn as much as possible about classes and packages in R, so this is of interest to me anyway.

Here is the skeleton of one of the .Rd files:

\name{as.POSIXct-methods}
\docType{methods}
\alias{as.POSIXct-methods}
\alias{as.POSIXct,ANY-method}
\alias{as.POSIXct,abc-method}
\title{\code{abc} Method for Function \code{as.POSIXct}}
\description{
\code{as.POSIXct} method to coerce timestamps in \code{abc} objects into 
\code{POSIXct} format.
}
\section{Methods}{
\describe{
~~description here~~

\item{\code{signature(x = "ANY")}}{
default implementation (from base)
}

\item{\code{signature(x = "abc")}}{
implementation for \code{\link{abc}} objects. 
~~more description of function~~
See \code{\linkS4class{abc}} for more about abc objects.
See also \code{\link[abc]{as.POSIXlt}} for the corresponding \code{POSIXlt} method.
}
}}
\keyword{methods}

The line fourth from the bottom is the one that is causing problems.

Was it helpful?

Solution

The basic format for a link is

\link{foo}

where foo appears in some help page (in the same package) as \alias{foo}. So if your other package has \alias{as.POSIXlt,abc-method} (pay attention to the absence of spaces) then

\link{as.POSIXlt,abc-method}

Adding [abc] is only necessary when linking to other packages, and then the semantics are confusing (in \link[abc]{foo}, foo is the name of the HTML help page, rather than, e.g., an alias). Adding \code{} is mark-up, so not directly relevant to establishing a link. The link above inserts "as.POSIXlt,abc-method" into the help page, which might be more informative (or not) than an arbitrary \alias tag that might be present.

OTHER TIPS

Per the Cross-references section of Writing R extensions, you can create links to other help pages like this:

\code{\link[base]{as.POSIXct}}

Where "base" is the name of the package (I don't think [base] is necessary, but if it were another package, it would be)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top