Show Documentation for Your R Function in Quarto on Click

R
Author

Filip Reierson

Published

April 30, 2024

In this article I share an approach to displaying documentation for user written functions in a quarto document using Tippy.js popups. The reason I started looking into this is that when I share progress in my PhD research I use a html document generated using quarto. In these reports I sometimes use functions that I have written myself which may not be fully self explanatory. To make it easier for someone reading my code, I decided to add documentation for these functions. However, navigating to a separate documentation page would interrupt the reader’s flow. Therefore, I developed my solution using the Tippy.js library.

Below is an example of the end result.

add(5,11)
[1] 16
multiply(5,5)
[1] 25

add: Add Together Two Numbers

Usage

add(x, y)

Arguments

  • x: A number.
  • y: A number.

Value

A number.

Description

Calculates the sum \(x+y\).

Examples

add(1, 1)
add(10, 1)

multiply: Multiply Together Two Numbers

Usage

multiply(x, y)

Arguments

  • x: A number.
  • y: A number.

Value

A number.

Description

Calculates the product \(x\times y\).

Examples

multiply(2,3)
multiply(7,10)

The code is available from freierson/docs-for-your-function-on-click-in-quarto. I admit this approach has many limitations and is not neat, but at the time of writing I have not found a better alternative for my particular use case. I hope others may also find it useful, at least as a starting point.