| Title: | Animated Terminal Demos for R via 'vhs' |
|---|---|
| Description: | Wraps the 'vhs' command-line tool from Charm (<https://github.com/charmbracelet/vhs>) so that animated GIF demos of R code can be produced from a single R expression. |
| Authors: | David Schoch [aut, cre] |
| Maintainer: | David Schoch <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.1 |
| Built: | 2026-06-04 06:43:45 UTC |
| Source: | https://github.com/schochastics/vhsR |
Captures the unevaluated R expression expr, types it line-by-line into
a freshly-spawned R session inside a vhs recording, and writes the
result to output. The R front-end is chosen by backend (see below).
Setup is a one-liner: if the required binaries are missing, the
function points to vhsr_install().
record_demo( expr, output = "demo.gif", ..., backend = c("auto", "arf", "radian", "R"), tape = NULL, quiet = FALSE )record_demo( expr, output = "demo.gif", ..., backend = c("auto", "arf", "radian", "R"), tape = NULL, quiet = FALSE )
expr |
An R expression (typically a |
output |
Path to the output file. The extension determines the
format ( |
... |
Pacing and styling arguments forwarded to |
backend |
Which interactive R front-end to record.
|
tape |
Optional. A raw |
quiet |
If |
Invisibly returns the path to the output file.
tape_options() for the full pacing/styling argument list.
## Not run: record_demo({ x <- 1:5 mean(x) head(cars, 3) }, output = "demo.gif") ## End(Not run)## Not run: record_demo({ x <- 1:5 mean(x) head(cars, 3) }, output = "demo.gif") ## End(Not run)
Reads path as R source, validates it parses, and records each line
typed into the recorded REPL. Equivalent to inlining the file
contents in record_demo() but accepts a path instead of an
expression.
record_demo_file( path, output = "demo.gif", ..., backend = c("auto", "arf", "radian", "R"), quiet = FALSE )record_demo_file( path, output = "demo.gif", ..., backend = c("auto", "arf", "radian", "R"), quiet = FALSE )
path |
Path to an R script file. |
output |
Path to the output file. The extension determines the
format ( |
... |
Pacing and styling arguments forwarded to |
backend |
Which interactive R front-end to record.
|
quiet |
If |
Invisibly returns output.
## Not run: record_demo_file("script.R", output = "demo.gif") ## End(Not run)## Not run: record_demo_file("script.R", output = "demo.gif") ## End(Not run)
Records the same R expression that record_demo() would, but
instead of (or in addition to) the animated output, writes a single
PNG frame using vhs's Screenshot directive.
record_demo_screenshot( expr, output = "demo.png", at = NULL, ..., backend = c("auto", "arf", "radian", "R"), quiet = FALSE )record_demo_screenshot( expr, output = "demo.png", at = NULL, ..., backend = c("auto", "arf", "radian", "R"), quiet = FALSE )
expr |
An R expression. See |
output |
Path to the output PNG. Must end in |
at |
Where to take the screenshot. |
... |
Pacing and styling arguments forwarded to |
backend |
Which interactive R front-end to record.
|
quiet |
If |
Invisibly returns output.
## Not run: record_demo_screenshot( { x <- 1:5; mean(x) }, output = "demo.png" ) ## End(Not run)## Not run: record_demo_screenshot( { x <- 1:5; mean(x) }, output = "demo.png" ) ## End(Not run)
The directory under tools::R_user_dir() where vhsr_install() places
downloaded vhs, ttyd, and ffmpeg binaries. The path is
platform-and-architecture-specific so a single $HOME can serve multiple
machines (e.g. via NFS).
vhsr_cache_dir()vhsr_cache_dir()
A length-1 character path. The directory is not created on read.
Silent variant: returns TRUE when vhs, ttyd, and ffmpeg can all
be located via vhsr_vhs_path() / vhsr_ttyd_path() /
vhsr_ffmpeg_path(), FALSE otherwise. Used at the top of
record_demo() to bail with an actionable error.
vhsr_check()vhsr_check()
TRUE or FALSE.
Prints two sections. The required binaries (vhs, ttyd, ffmpeg)
are reported one per line with name, version, where they were found
(cache or system), and full path. The optional highlighting tools
(arf, radian) are reported below with install hints
when missing. If any required binary is missing, a one-line
vhsr_install() call is suggested at the end.
vhsr_doctor()vhsr_doctor()
Invisibly returns the result of vhsr_check().
Downloads vhs, ttyd, and ffmpeg into the per-user cache returned by
vhsr_cache_dir(). Where binaries cannot be auto-downloaded for a given
platform (notably ttyd and ffmpeg on macOS), the function aborts with
a one-line brew install instruction; system-installed binaries on
PATH are picked up automatically by vhsr_doctor() afterwards.
vhsr_install( tools = c("vhs", "ttyd", "ffmpeg"), force = FALSE, versions = list() )vhsr_install( tools = c("vhs", "ttyd", "ffmpeg"), force = FALSE, versions = list() )
tools |
Character vector of tools to install. Defaults to all three. |
force |
If |
versions |
A named list overriding the default version of any tool,
for example |
Invisibly returns the cache directory path.
Each function returns the first match in this order:
option (vhsR.<tool>_path) -> env var (VHSR_<TOOL>) -> per-user cache
(see vhsr_cache_dir()) -> system PATH. Returns "" when nothing
matches.
vhsr_vhs_path() vhsr_ttyd_path() vhsr_ffmpeg_path() vhsr_radian_path() vhsr_arf_path()vhsr_vhs_path() vhsr_ttyd_path() vhsr_ffmpeg_path() vhsr_radian_path() vhsr_arf_path()
A length-1 character path, or "" if not found.
Escape hatch for users who want full control over the vhs script. Pass
either a path to a .tape file or the tape contents as a string.
vhsr_run_tape(tape, quiet = FALSE)vhsr_run_tape(tape, quiet = FALSE)
tape |
Path to a |
quiet |
If |
Invisibly returns the processx::run() result.
Returns an htmltools::tagList() containing the recorded GIF /
video, suitable for embedding in an Rmarkdown chunk
(results = "asis") or a Shiny UI. Auto-detects the format from
file's extension: .gif becomes a styled <img>,
.mp4 / .webm become a <video controls loop muted playsinline>.
vhsr_widget(file, width = NULL, height = NULL)vhsr_widget(file, width = NULL, height = NULL)
file |
Path to a |
width, height
|
Optional CSS dimensions. Numeric values are
treated as pixels (e.g. |
An htmltools::tagList.
## Not run: record_demo({ x <- 1:5; mean(x) }, output = "demo.gif") vhsr_widget("demo.gif") ## End(Not run)## Not run: record_demo({ x <- 1:5; mean(x) }, output = "demo.gif") vhsr_widget("demo.gif") ## End(Not run)