downlit icon indicating copy to clipboard operation
downlit copied to clipboard

rd2html doesn't handle all links correctly

Open nealrichardson opened this issue 1 year ago • 0 comments

I'm trying to add documentation to arrow that links to all of the functions in other R packages that are supported in arrow queries: https://github.com/apache/arrow/pull/14014

I generate roxygen2 markdown with links to the original functions, like this: https://github.com/apache/arrow/pull/14014/files#diff-8e2b0f2944713c80b312477fd9e90bf65071251dd380b84940127cc167c7b55aR150

This turns into Rd: https://github.com/apache/arrow/pull/14014/files#diff-95f5533b9053bd8ef110bf03a4e1e97f7631a42639ed1603e191856145ac1b7aR136

But when I render the pkgdown site, some of those links don't convert to hrefs. The ones that don't are:

  • base:MathFun
  • base:Round
  • base:Log
  • base:Extremes
  • lubridate:date_utils
  • lubridate:posix_utils

Reprex:

> pkgdown::rd2html("\\link[base:Extremes]{something}")
[1] "something"

The documentation URLs do in fact exist, e.g. https://rdrr.io/r/base/Round.html and https://lubridate.tidyverse.org/reference/date_utils.html.

What they all have in common is that the topic name does not match the object or function being documented. But there are other topics where that is also true but the linking works:

> pkgdown::rd2html("\\link[base:Extract]{something}")
[1] "<a href='https://rdrr.io/r/base/Extract.html'>something</a>"

Interestingly, though, ?Extract does successfully open the help page, but ?Log or ?Extremes etc. do not.

I poked around in the internals at where the lookup happens and noticed this:

> x <- downlit:::topic_index("base")
# This case works: topic is in the names
> "Extract" %in% names(x)
[1] TRUE
> "Extract" %in% x
[1] TRUE
# This does not work: topic not in names
> "Extremes" %in% names(x)
[1] FALSE
> "Extremes" %in% x
[1] TRUE

Digging further, I noticed that you do get a link if the Rd points at the function name and not the topic for these:

> pkgdown::rd2html("\\link[base:max]{something}")
[1] "<a href='https://rdrr.io/r/base/Extremes.html'>something</a>"

So maybe this is a roxygen2 issue, or a downlit issue.

nealrichardson avatar Sep 12 '22 13:09 nealrichardson