# A simple REPL (R eval/process loop) using basic features of processSocket()
repl <- function ()
{
pars <- parSocket("repl", "", bare = FALSE) # Parameterize the loop
cat("Enter R code, hit <CTRL-C> or <ESC> to exit\n> ") # First prompt
repeat {
entry <- readLines(n = 1) # Read a line of entry
if (entry == "") entry <- "<<<esc>>>" # Exit from multiline mode
cat(processSocket(entry, "repl", "")) # Process the entry
}
}
repl()Run the code above in your browser using DataLab