Skip to content

Commit

Permalink
feat(pkgdown): Add auto-linking for R6 objects
Browse files Browse the repository at this point in the history
  • Loading branch information
RasmusSkytte committed Oct 29, 2024
1 parent 0bd07c3 commit 38b669b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,29 @@ jobs:
# We also remove the surplus entry for the classes with spaces
sed -i 's/<code><a href="\(\w\+\)\.html">\w\+\.[a-zA-Z_ ]\+<\/a><\/code>//g' docs/reference/index.html
- name: Remove question marks from auto-linked references
run: |
# The only way to auto-link R6 objects is by prepending af `?` to the code block
# For specific functions in an R6 class, it is possible to prepend the parent class `?parent$function()`
# Here we filter out these prepended blocks to generate a cleaner documentation.
# Fixing "?R6class"
# The links to the internal R6 classes have the following format when generated by pkgdown:
# <a href="../reference/FeatureHandler.html">?FeatureHandler</a>
# We remove the question mark to make the link cleaner
# regex: <a href="\.\.\/([\/\w]+.html)">\?(\w+)<\/a>
find docs -type f -exec sed -i 's/<a href="\.\.\/\([\/\w]\+\.html\)">\?\(\w\+\)<\/a>/<a href="\1">\2<\/a>/g' {} +
# Fixing "?R6class$function()"
# pkgdown does not generate links for this type of reference, so we need to create the link fully manually
# The code has the following format when generated by pkgdown
# <code>?DiseasystoreBase$available_observables</code>
# We need to manually create the link to the function
# regex: <code>\?(\w+)\$()(\w+\(\))<\/code>
# Target: <a href="../reference/DiseasystoreBase.html#method-DiseasystoreBase-get_feature"><code>get_feature()</code></a>
find docs -type f -exec sed -i 's/<code>\?\(\w\+\)\$\(\w\+\(\)\)<\/code>/<a href="\.\.\/reference\/\1.html#method-\1-\2"><code>\2<\/code><\/a>/g' {} +
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
Expand Down
10 changes: 8 additions & 2 deletions workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,16 @@ If this generate changes the `.Rd` files, it will commit the updated documentati
#### Trigger
Pushes or pull requests to the main branch if there are changes to any file in the `R/`, `man/` or `vignette/` folders.

Special triggering on creation of a `release`
Special triggering on creation of a `release`.

#### Function
Generates the `pkgdown` documentation for your package
Generates the `pkgdown` documentation for your package.

> [!IMPORTANT]
> This workflow runs additional formatting of the pkgdown documentation.
> Specifically, it adds auto-linking to R6 object
> - `?MyR6Class` is rendered without the `?` and links to `MyR6Class`.
> - `?MyR6Class$method()` is rendered as `method()` and links to the method of `MyR6Class`
#### Outcome
The output of `pkgdown` is stored as an artifact on github.
Expand Down

0 comments on commit 38b669b

Please sign in to comment.