MyNixOS website logo
Description

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.

Metadata

Version

2.3.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows