| Title: | Simulate Typing Script |
|---|---|
| Description: | Simulates typing of R script files for presentations and demonstrations. Provides character-by-character animation with optional live code execution. Supports R scripts (.R), R Markdown (.Rmd), and Quarto (.qmd) documents. |
| Authors: | Federica Gazzelloni [aut, cre] |
| Maintainer: | Federica Gazzelloni <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.1 |
| Built: | 2026-05-09 08:00:41 UTC |
| Source: | https://github.com/fgazzelloni/typer |
Simulates typing out the content of an R script file, line by line, character by character, to create an animation effect for live coding presentations or educational demonstrations.
typeR(file, delay = 0.05)typeR(file, delay = 0.05)
file |
Path to the R script file to simulate typing. |
delay |
The delay (in seconds) between typing each character (default: 0.05). |
Invisibly returns NULL. Called for the side effect of displaying typed content in the console with animation.
# Create a temporary R script for demonstration tmp <- tempfile(fileext = ".R") writeLines(c( "# Example R script", "x <- 1:10", "mean(x)" ), tmp) # Simulate typing the script (fast for testing) typeR(tmp, delay = 0.01) # Clean up unlink(tmp) # Longer example with realistic typing speed tmp2 <- tempfile(fileext = ".R") writeLines(c( "# Data analysis example", "data <- mtcars", "model <- lm(mpg ~ wt, data = data)", "summary(model)" ), tmp2) typeR(tmp2, delay = 0.08) unlink(tmp2)# Create a temporary R script for demonstration tmp <- tempfile(fileext = ".R") writeLines(c( "# Example R script", "x <- 1:10", "mean(x)" ), tmp) # Simulate typing the script (fast for testing) typeR(tmp, delay = 0.01) # Clean up unlink(tmp) # Longer example with realistic typing speed tmp2 <- tempfile(fileext = ".R") writeLines(c( "# Data analysis example", "data <- mtcars", "model <- lm(mpg ~ wt, data = data)", "summary(model)" ), tmp2) typeR(tmp2, delay = 0.08) unlink(tmp2)
An enhanced version of typeR that not only simulates typing but also
evaluates R code in real-time. Supports interactive pause/resume control and handles
both Quarto/R Markdown documents and plain R scripts.
typeRun( file, delay = 0.05, jitter = 0.01, max_print = 10, envir = new.env(parent = .GlobalEnv) )typeRun( file, delay = 0.05, jitter = 0.01, max_print = 10, envir = new.env(parent = .GlobalEnv) )
file |
Character string. Path to an R script (.R), R Markdown (.Rmd), or Quarto (.qmd) file to type and execute. |
delay |
Numeric. Base delay in seconds between typing each character. Default is 0.05 (50 milliseconds). |
jitter |
Numeric. Standard deviation for random variation in typing speed, adding natural typing rhythm. Default is 0.01. |
max_print |
Integer. Maximum number of elements to print for long outputs (vectors, data frames, matrices, lists). Default is 10. |
envir |
Environment. The environment in which to evaluate R code. Default is a new environment with the global environment as parent. |
typeRun() extends the basic typeR() functionality by:
Live Code Evaluation: Executes R code chunks as they are typed
Interactive Control: Press ESC/Ctrl+C to pause, then choose to resume or stop
Smart Output: Truncates long outputs and handles models intelligently
Format Support: Handles .R, .Rmd, and .qmd files intelligently
For Quarto/R Markdown files, typeRun():
Skips YAML headers
Only evaluates code in R code chunks
Preserves narrative text without evaluation
For R scripts, it evaluates all non-comment, non-empty lines.
Invisibly returns NULL. Called for side effects (typing animation
and code evaluation).
Assignments and plotting functions execute silently
Long vectors/data frames are truncated to max_print elements
Model summaries (lm, glm, etc.) display using R's standard print methods
Raw model objects (without summary call) show a simple fitted message
Package loading messages (library/require) are suppressed
Errors are caught and displayed without stopping execution
During execution, you can:
Press ESC (or Ctrl+C on some systems) to pause
Enter 1 to resume from where you paused
Enter 2 to stop completely
typeR for typing without evaluation
# Create a temporary R script for demonstration tmp <- tempfile(fileext = ".R") writeLines(c( "# Simple calculation", "x <- 1:5", "print(mean(x))", "y <- x^2", "print(sum(y))" ), tmp) # Type and run with fast animation (for quick testing) typeRun(tmp, delay = 0.01, max_print = 5) # Clean up unlink(tmp) # Interactive examples with real files if (interactive()) { # Type and run a simple R script typeRun("analysis.R") # Type and run with slower, more dramatic effect typeRun("demo.R", delay = 0.1, jitter = 0.02) # Type and run a Quarto document with limited output typeRun("report.qmd", max_print = 5) }# Create a temporary R script for demonstration tmp <- tempfile(fileext = ".R") writeLines(c( "# Simple calculation", "x <- 1:5", "print(mean(x))", "y <- x^2", "print(sum(y))" ), tmp) # Type and run with fast animation (for quick testing) typeRun(tmp, delay = 0.01, max_print = 5) # Clean up unlink(tmp) # Interactive examples with real files if (interactive()) { # Type and run a simple R script typeRun("analysis.R") # Type and run with slower, more dramatic effect typeRun("demo.R", delay = 0.1, jitter = 0.02) # Type and run a Quarto document with limited output typeRun("report.qmd", max_print = 5) }