pco: Print commands only

Description Usage Details See Also Examples

View source: R/ccopy.R

Description

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.

Usage

1
pco()

Details

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).

See Also

cco, rco

Examples

 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)
# [1] 15
## The following line does this copying:
writeLines(c("> a <- 10", "> b <- 5", "> sum(a,", "+ b)", "[1] 15"),
  "clipboard")

## Print commands only:
pco()
## The following output is printed:
# a <- 10
# b <- 5
# sum(a,
# b)

ljrendell/ccopy documentation built on May 21, 2017, 1:41 p.m.