Description Usage Details See Also Examples
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 write these remaining lines back to the clipboard.
1 | cco()
|
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 written to the clipboard in order that it may be pasted by the user.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ## Suppose the following (uncommented) lines are copied to the clipboard:
# > a <- 10
# > b <- 5
# > sum(a,
# + b)
# [1] 15
## The following line does this copying:
writeLines(c("> a <- 10", "> b <- 5", "> sum(a,", "+ b)", "[1] 15"),
"clipboard")
## Copy commands only:
cco()
## Pasting from the clipboard gives the following (uncommented) lines:
# 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.