Create 'Ascii' Screen Casts from R Scripts

Record 'asciicast' screen casts from R scripts. Convert them to animated SVG images, to be used in 'README' files, or blog posts. Includes 'asciinema-player' as an 'HTML' widget, and an 'asciicast' 'knitr' engine, to embed 'ascii' screen casts in 'Rmarkdown' documents.


asciicast

Turn R scripts into terminal screencasts

Lifecycle:experimental CRANstatus Codecov testcoverage R-CMD-check

asciicast takes an R script and turns it into an asciinema cast. It can simulate typing, and records all terminal output in real time as it happens.

Features

  • Input is an R script, output is a v2 asciicast recording.
  • Record all terminal output in real time, as it happens.
  • Simulate typing in the commands, with a configurable, randomized speed.
  • Alternatively, whole comment blocks or expressions can just appear on the screen.
  • Convert casts to SVG images using svg-term. The package comes with its own svg-term bundle, no external dependencies are needed.
  • Render a single frame of a cast as an SVG image.
  • Configurable delay at the beginning, at the end and between paragraphs.
  • HTML widget, to be used in Rmarkdown documents, e.g. in vignettes.
  • Read casts from asciinema JSON files (version 2), or from https://asciinema.org directly.
  • Special knitr engine to create R markdown files with ascii casts. See the asciicast-demo vignette.
  • Create ascii casts in GitHub READMEs via animated SVG files. See an example in inst/examples or the README.Rmd source of the README file you are reading.

Limitations

Installation

You can install the released version of asciicast from CRAN:

install.packages("asciicast")

Examples

See the inst/examples directory for these examples.

Hello world

The input script:

print("Hello world!")

The result:

Asciicast demo in asciicast

Input script that uses asciicast itself:

#' Title: asciicast example recorded in asciicast
#' Empty_wait: 3
#' End_wait: 20

# An example for using asciicast, recorded in asciicast itself!      #!

# First, save the R code you want to run, in a script file.          #!
# The file can contain any code, including interactive code,         #!
# as long as it is a syntactically valid R file.                     #!

# Second, perform the recording with the `record()` function.        #!
# We are recording an example file now, that comes with the package. #!

src <- system.file("examples", "hello.R", package = "asciicast")
cast <- asciicast::record(src)

# `cast` is an `asciicast` object, which has some metadata and the   #!
# recording itself:                                                  #!

cast

# You can write `cast` to a JSON file that can be played by any      #!
# asciinema player. Or you can write it to an SVG file that can      #!
# be embedded into a web page, or a GitHub README.                   #!

svg <- tempfile(fileext = ".svg")
asciicast::write_svg(cast, svg, window = TRUE)

Errors are recorded

Input script with errors:

#' End_wait: 20
# Demonstrate that errors are handled well

# Base R error
library("not-this-really")
traceback()

# callr errors are saved to `.Last.error`, including a stack trace
library(cli)
callr::r(function() library("another-failure"))
.Last.error

Related tools

License

MIT @ RStudio

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("asciicast")

2.3.1 by Gábor Csárdi, 3 years ago


https://asciicast.r-lib.org/, https://github.com/r-lib/asciicast


Report a bug at https://github.com/r-lib/asciicast/issues


Browse source code at https://github.com/cran/asciicast


Authors: Gábor Csárdi [aut, cre] , Romain Francois [aut] , Mario Nebl [aut] (https://github.com/marionebl/svg-term author) , Marcin Kulik [aut] (https://github.com/asciinema/asciinema-player author) , Posit Software , PBC [cph, fnd]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports cli, curl, jsonlite, magick, processx, tibble, utils, V8, withr

Suggests callr, covr, cpp11, decor, htmlwidgets, knitr, mockery, rmarkdown, rstudioapi, testthat

Linking to processx


Suggested by cTOST, callr, maestro, pkgdepends, rhub.


See at CRAN