Skip to contents

Builds your pkgdown site, opens it in your browser, and automatically rebuilds and refreshes whenever you save a change. The R console stays busy until you press Ctrl+C to stop the server; use preview() instead if you want to keep using R while the preview runs.

Usage

serve(
  pkg = ".",
  document = TRUE,
  strategy = c("smart", "lazy", "full"),
  port = 4321,
  browse = interactive(),
  quiet = FALSE,
  theme = getOption("updoc.theme", "auto"),
  pandoc = getOption("updoc.pandoc", NULL)
)

Arguments

pkg

Path to an R package (or any file or folder inside it). Defaults to the current directory (".").

document

Whether to re-run roxygen2 when files in R/ change. Set to FALSE if you manage man/ files yourself. R syntax is still checked, and README.Rmd is still rendered when edited.

strategy

How to rebuild after you save a file:

  • "smart" (default): rebuilds only the pages affected by your edit, and does a full build for broader changes like _pkgdown.yml, DESCRIPTION, or R code.

  • "lazy": lets pkgdown skip reference pages and articles that are already up to date.

  • "full": rebuilds the whole site on every save.

port

Preferred local port for the preview server (defaults to 4321). Use 0 to pick any free local port automatically. If a specific port is already in use, updoc picks another free port.

browse

Whether to open the preview in your browser right away. Defaults to TRUE in interactive R sessions and FALSE otherwise.

quiet

Whether to hide detailed pkgdown output in the console. Build progress, warnings, and errors are still shown.

theme

Color scheme for the in-browser status popup:

  • "auto" (default): matches the site's light or dark theme, falling back to your system preference.

  • "inverse": uses the opposite of "auto" for extra contrast.

  • "light" or "dark": keeps the popup in that theme.

Override the default across sessions with options(updoc.theme = ...).

pandoc

Path to the directory containing the pandoc binary (version 2.10.1 or newer). When NULL (the default), updoc uses the Pandoc found by rmarkdown. Set options(updoc.pandoc = "/path/to/bin") to reuse a specific directory across builds. updoc never downloads Pandoc or changes your system installation.

Value

Invisibly, the stopped updoc_preview handle.

Details

Previews run in a temporary copy of your package, so your man/ files, README.md, and docs/ folder stay untouched. Use check() for a one-shot non-destructive build check, or build() when you are ready to build the site for publishing.

Examples

if (interactive()) {
  # Run from your package directory. Press Ctrl+C to stop.
  serve()
}