Take the content of the system clipboard (assumed to contain text copied from
the R console), delete any lines of text not commencing with
"> " or
"+ ", delete these characters from the beginning of all remaining
lines, and then execute these remaining lines in the console.
Arguments to be passed to
This function should be run when the system clipboard contains text
copied from the R console.
"> " is the default console command
prompt in R, and
"+ " is the default console continuation prompt;
deleting all lines of text that do not commence with these strings is
intended to delete all lines that do not correspond to user commands (such
as lines of output, or error/warning messages). From these remaining lines,
the first two characters (either
"> " and
"+ ") are deleted.
The resulting lines comprise executable R code, comprising only the user
commands from the original console text. This code is executed using the
source, to which any arguments are passed (e.g.
echo = TRUE causes each expression to be printed before evaluation).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#' ## Suppose the following (uncommented) lines are copied to the clipboard: # > a <- 10 # > b <- 5 # > sum(a, # + b) #  15 ## The following line does this copying: writeLines(c("> a <- 10", "> b <- 5", "> sum(a,", "+ b)", " 15"), "clipboard") ## Run commands only: rco() ## Check assigned value of a (should be 10): a
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.