::install_github('r-lib/asciicast', ref = remotes::github_pull(24)) remotes
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
<- "nzchar.R"
src <- asciicast::record(src)
cast
# <<
# `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.
# <<
<- tempfile(fileext = "gif")
svg ::write_gif(cast, svg, theme = "monokai") asciicast
Really fun for adding to tweets!