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 toFALSEif you manageman/files yourself. R syntax is still checked, andREADME.Rmdis 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). Use0to 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
TRUEin interactive R sessions andFALSEotherwise.- 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
pandocbinary (version 2.10.1 or newer). WhenNULL(the default), updoc uses the Pandoc found by rmarkdown. Setoptions(updoc.pandoc = "/path/to/bin")to reuse a specific directory across builds. updoc never downloads Pandoc or changes your system installation.
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 thebuild_logfile 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 untiltimeoutseconds pass), and return the current status. Passafter(a previousrebuild_count) to wait until a newer build finishes or fails.$rebuild(full = FALSE): trigger a manual rebuild (passfull = TRUEto rebuild the entire site).$open(): open the preview in your browser again.$stop(): stop watching files and shut down the server.
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.
Examples
if (interactive()) {
# Run from your package directory.
site <- preview()
site$status()
site$rebuild()
# Stop the server when you are done.
site$stop()
}