typeRun() is an enhanced version of typeR()
that not only simulates typing animation but also executes your
R code in real-time. This makes it perfect for:
The most basic usage is to run an R script with typing animation and live execution:
# Create a simple script
cat("# Data Analysis Demo
x <- 1:10
mean(x)
sum(x)
", file = "demo.R")
# Type and execute it
typeRun("demo.R")What youβll see:
cat("
# Linear regression
model <- lm(mpg ~ hp + wt, data = mtcars)
summary(model)
", file = "model_demo.R")
typeRun("model_demo.R")What happens:
model <- lm(...) executes silently (no output)summary(model) displays the full summary with
coefficients, R-squared, etc.typeRun() handles all model types intelligently:
The typeRun() function properly displays statistical
test results using their formatted print methods:
library(typeR)
# Create a test script
cat('x <- rnorm(50, mean = 20, sd = 3)
tt <- t.test(x, alternative = "two.sided", conf.level = 0.95)
tt
', file = "test_ttest.R")
# Run it
typeRun("test_ttest.R", delay = 0.01)This will display the t-test results in their proper formatted output:
One Sample t-test
data: x
t = 45.185, df = 49, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
18.68753 20.42711
sample estimates:
mean of x
19.55732
The same applies to other statistical objects like
anova(), aov(), lm(), etc.
During execution, you have full control:
Enter choice (1 resume or 2 stop):This is perfect for:
typeRun() intelligently handles .Rmd
files:
Behavior:
Run code in an isolated environment to keep your workspace clean:
Package loading messages are automatically suppressed:
cat("
library(ggplot2) # No startup message shown
library(dplyr) # Clean output
# But code works normally
mtcars %>% head()
", file = "packages.R")
typeRun("packages.R")
# Shows only the actual results, not package messagesThese donβt produce output (cleaner demos):
cat("
# Load data
data(mtcars)
head(mtcars, 3)
# Visualize relationship
plot(mtcars$hp, mtcars$mpg,
xlab = 'Horsepower',
ylab = 'Miles per Gallon',
main = 'MPG vs Horsepower')
# Fit model
model <- lm(mpg ~ hp, data = mtcars)
summary(model)
# Add regression line
abline(model, col = 'red', lwd = 2)
# Predictions
new_data <- data.frame(hp = c(100, 150, 200))
predict(model, new_data)
", file = "teaching_demo.R")
typeRun("teaching_demo.R", delay = 0.08)cat("
# 1. Load and explore
data <- iris
str(data)
# 2. Summary statistics
summary(data)
# 3. Visualization
boxplot(Sepal.Length ~ Species, data = data,
main = 'Sepal Length by Species',
col = c('lightblue', 'lightgreen', 'pink'))
# 4. Statistical test
aov_result <- aov(Sepal.Length ~ Species, data = data)
summary(aov_result)
# 5. Post-hoc test
TukeyHSD(aov_result)
", file = "analysis_demo.R")
typeRun("analysis_demo.R", delay = 0.06, max_print = 8)cat("
# Binary outcome: Manual transmission (am)
# Predictors: HP and weight
# Fit logistic regression
logit_model <- glm(am ~ hp + wt,
data = mtcars,
family = binomial(link = 'logit'))
# Model summary
summary(logit_model)
# Odds ratios
exp(coef(logit_model))
# Predicted probabilities
mtcars$pred_prob <- predict(logit_model, type = 'response')
head(mtcars[, c('am', 'hp', 'wt', 'pred_prob')])
", file = "glm_example.R")
typeRun("glm_example.R", max_print = 6)Before presenting:
| Feature | typeR() |
typeRun() |
|---|---|---|
| Typing animation | β | β |
| Code execution | β | β |
| Shows output | β | β |
| Interactive pause/resume | β | β |
| Output truncation | β | β |
| Custom environment | β | β |
| Model summary handling | N/A | β |
| Library message suppression | N/A | β |
?typeR - Basic typing animation without execution?typeRun - Full function documentation