Package 'updoc'

Title: Live Preview Server for 'pkgdown' Sites
Description: Serves live previews of 'pkgdown' sites while you edit your package. Watches for saved changes, rebuilds affected pages, refreshes the browser, and displays build progress, warnings, and errors. Keeps the last working preview available if a build fails, and leaves generated files in your source package untouched while previewing.
Authors: Leighton Payne [aut, cre, cph] (ORCID: <https://orcid.org/0000-0003-2305-6827>), shadcn [cph] (Adapted preview interface patterns and design tokens), Lucide Icons and Contributors [cph] (Preview icons), Cole Bemis [cph] (Feather-derived preview icon)
Maintainer: Leighton Payne <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-11-25 18:23:14 UTC
Source: https://github.com/leightonpayne/updoc

Help Index


Build your pkgdown site for publishing

Description

Builds a complete pkgdown site ready to deploy. Use serve() or preview() for a live preview while you edit, or check() to verify the site in a temporary copy without modifying files in your package.

Usage

build(
  pkg = ".",
  destination = NULL,
  document = TRUE,
  lazy = FALSE,
  quiet = FALSE,
  pandoc = getOption("updoc.pandoc", NULL)
)

Arguments

pkg

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

destination

Optional output folder to write the site into instead of pkgdown's default. Relative paths are resolved from the package root.

document

Whether to run roxygen2 before building. Set to FALSE if you manage ⁠man/⁠ files yourself. Even when FALSE, README.Rmd is still rendered if present.

lazy

Whether to skip rebuilding reference pages and articles whose output is already newer than their source files.

quiet

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

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.

Details

Unlike a live preview, build() writes directly to your package: it updates roxygen documentation (unless document = FALSE), renders README.Rmd to README.md if present, and builds the site into your configured pkgdown output folder (usually ⁠docs/⁠). It does not upload the site anywhere; publish that folder with your usual hosting setup.

Value

Invisibly, an updoc_build object with package_root, site_dir, duration, lazy, and build_log. The full build log is saved in the current R session's temporary directory; if a build fails, the error message includes the log path and the error condition carries it in ⁠$build_log⁠.

Examples

if (interactive()) {
  # Run from your package directory when you are ready to publish.
  build()
}

Check a pkgdown site without modifying your package

Description

Validates your package sources and builds the pkgdown site in a temporary copy, leaving your ⁠man/⁠ files, NAMESPACE, README.md, and ⁠docs/⁠ folder untouched. Handy in CI, scripts, and AI agent edit-verify loops.

Usage

check(
  pkg = ".",
  document = TRUE,
  quiet = FALSE,
  format = c("text", "json"),
  error = TRUE,
  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 run roxygen2 in the temporary copy before building. Set to FALSE if you manage ⁠man/⁠ files yourself. R syntax is still checked, and README.Rmd is still rendered if present.

quiet

Whether to hide detailed pkgdown output. Always treated as TRUE when format = "json" so standard output stays valid JSON.

format

Output format:

  • "text" (default): print a readable summary and structured diagnostics.

  • "json": print one JSON object (ok, package_root, duration, warnings, error, and build_log) to standard output.

error

Whether to signal an error if the build fails. Defaults to TRUE so ⁠Rscript -e "updoc::check()"⁠ exits with a non-zero status on failure. Set to FALSE to inspect the returned updoc_check object without throwing.

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.

Details

Like serve() and preview(), check() checks R syntax and article YAML front matter, runs roxygen2 (unless document = FALSE), renders README.Rmd if present, and builds the site in isolation. Temporary site files are deleted before returning, while the full build log stays in the current R session's temporary directory.

Value

Invisibly, an updoc_check object with ok, package_root, duration, warnings, error, and build_log. When error = TRUE and the check fails, the thrown error message includes the log path and the condition carries ⁠$build_log⁠ and ⁠$check⁠.

Examples

if (interactive()) {
  # Verify the site without touching generated files in your package.
  check()

  # Emit machine-readable JSON for scripts or AI agents.
  check(format = "json", error = FALSE)
}

Start a background live pkgdown preview

Description

Starts the same live preview server as serve(), then returns right away so you can keep working in the R console. Assign the result (for example, site <- preview()) to check status, trigger rebuilds, or stop the server later.

Usage

preview(
  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.

Details

Previews build in a temporary copy of your package, leaving your ⁠man/⁠ files, README.md, and ⁠docs/⁠ folder untouched. Edits to README.Rmd are rendered automatically, and if a build fails, your last working preview stays up until you fix the error and save again.

Value

Invisibly, an updoc_preview handle with url and package_root fields. Print the handle to see its current status, or call its methods:

  • ⁠$status()⁠: inspect build status, warnings, errors, and the build_log file path (kept for the current R session).

  • ⁠$wait(timeout = 60, after = NULL)⁠: check for any newly saved changes, wait until the preview finishes building (or until timeout seconds pass), and return the current status. Pass after (a previous rebuild_count) to wait until a newer build finishes or fails.

  • ⁠$rebuild(full = FALSE)⁠: trigger a manual rebuild (pass full = TRUE to rebuild the entire site).

  • ⁠$open()⁠: open the preview in your browser again.

  • ⁠$stop()⁠: stop watching files and shut down the server.

Examples

if (interactive()) {
  # Run from your package directory.
  site <- preview()
  site$status()
  site$rebuild()
  # Stop the server when you are done.
  site$stop()
}

Serve a live pkgdown preview

Description

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.

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.

Value

Invisibly, the stopped updoc_preview handle.

Examples

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