remotes::install_github('r-lib/asciicast', ref = remotes::github_pull(24)) How to create a GIF of code and its output
We can create a GIF of code and its output using asciicast.
Install the development version:
Create a file called nzchar.R with specifications for the GIF and the code to run.
#' Title: Using nzchar
#' Columns: 60
#' Rows: 18
# This is not empty
Sys.getenv("R_LIBS_USER")
# This is empty
Sys.getenv("test")
# This returns TRUE
nzchar(Sys.getenv("R_LIBS_USER"))
# This returns FALSE
nzchar(Sys.getenv("test"))Create another file that creates the GIF:
#' Title: Using nzchar
src <- "nzchar.R"
cast <- asciicast::record(src)
# <<
# `cast` is an `asciicast` object, which has some metadata and the
# recording itself:
# <<
cast
# <<
# You can write `cast` to a GIF file with the version installed above.
# <<
svg <- tempfile(fileext = "gif")
asciicast::write_gif(cast, svg, theme = "monokai")Really fun for adding to tweets!
