Demo <- function(x) { require(evaluate) xx <- evaluate(file(x)) tmp <- function(y){replay(y);invisible(readline())} invisible(lapply(xx, tmp)) } # avoid unnecessary blank lines as possible Demo2 <- function(x) { require(evaluate) xx <- evaluate(file(x)) tmp <- function(y){ yy <- y z <- substr(yy,1,nchar(yy)-1) if(class(yy)[1] == "source") yy <- paste("> ", z, sep="") else if(class(yy)[1] == "character") yy <- z replay(yy) invisible(readline())} invisible(lapply(xx, tmp)) } DemoAux <- function(x) evaluate(file(x)) # Demo(x) is equivalent to Demo0(DemoAux(x)) Demo0 <- function(x) { require(evaluate) tmp <- function(y){replay(y);invisible(readline())} invisible(lapply(x, tmp)) } # Demo2(x) is equivalent to Demo20(DemoAux(x)) Demo20 <- function(x) { require(evaluate) tmp <- function(y){ yy <- y z <- substr(yy,1,nchar(yy)-1) if(class(yy)[1] == "source") yy <- paste("> ", z, sep="") else if(class(yy)[1] == "character") yy <- z replay(yy) invisible(readline())} invisible(lapply(x, tmp)) }