r-lib / downlit

Syntax Highlighting and Automatic Linking
https://downlit.r-lib.org
Other
90 stars 22 forks source link

Auto-linking to documentation for re-exported S3 methods #194

Open dtburk opened 4 months ago

dtburk commented 4 months ago

Package ipumsr re-exports haven::as_factor() to give users easy access to the S3 method haven:::as_factor.haven_labelled() defined in haven. However, since the generic is defined in forcats, downlit links references to as_factor() in ipumsr documentation to the forcats::as_factor() documentation (see reprex below).

library(ipumsr)
library(downlit)

href_topic("as_factor", package = "ipumsr", is_fun = TRUE)
#> [1] "https://forcats.tidyverse.org/reference/as_factor.html"

Created on 2024-07-08 with reprex v2.1.1

This autolinking behavior is technically correct, but it would be useful if there was an option for ipumsr developers to specify that we want calls to as_factor() to link to the haven documentation, since that is more relevant to our users.

dmurdoch commented 4 months ago

Would href_topic("as_factor.labelled", package = "haven", is_fun = TRUE) work? Or do you need this to happen automatically when downlit sees as.factor?

dtburk commented 4 months ago

Thanks for the quick reply!

Ideally it would happen automatically, so that we can just call as_factor() in example code in a vignette, and have the auto-generated link on our pkgdown website point to the haven documentation.

Since our use case for downlit is through pkgdown, I'm imagining that this feature, were it ever created, might require tweaks to both pkgdown and downlit (e.g. a new field in _pkgdown.yml specifying that as_factor() should be treated as haven:::as_factor.haven_labelled()).