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 print these remaining lines in the console.
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 is printed as output in the R console (though not executed).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
## 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") ## Print commands only: pco() ## The following output is printed: # a <- 10 # b <- 5 # sum(a, # b)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.