Skip to content

Instantly share code, notes, and snippets.

@muschellij2
Created March 4, 2019 03:04
Show Gist options
  • Save muschellij2/a788c5c24df32052216e82d314f6c8da to your computer and use it in GitHub Desktop.
Save muschellij2/a788c5c24df32052216e82d314f6c8da to your computer and use it in GitHub Desktop.
Take an R Script and make it into a gif.
library(rsciinema)
input = paste0("library(magrittr); # a comment is a gra", backspace(), "eat thing to do",
"\niris %>% \n dplyr::group_by(Species) %>%\n ",
"dplyr::summarise_all(mean) \n # a new line")
data = asciicast( input )
json = rsciinema::json_asciicast(data)
tfile = tempfile(fileext = ".json")
writeLines(json, con = tfile)
gif = tempfile(fileext = ".gif")
cmd = paste("asciicast2gif", tfile, gif)
system(cmd)
svg = tempfile(fileext = ".svg")
cmd = paste("cat", tfile, "|", "svg-term --out ", svg)
system(cmd)
input = paste0("library(magrittr); # a comment is a gra", backspace(), "eat thing to do",
"\niris %>% \n dplyr::group_by(Species) %>%\n ",
"dplyr::summarise_all(mean) \n # a new line")
data = asciicast( input )
# extend time to look at the data
ind = grep("A tibble", data$text)
data$time[ind + 1] = data$time[ind + 1] + 5
json = rsciinema::json_asciicast(data)
tfile = tempfile(fileext = ".json")
writeLines(json, con = tfile)
svg = tempfile(fileext = ".svg")
cmd = paste("cat", tfile, "|", "svg-term --out ", svg)
system(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment