rco: Run commands only

Description Usage Arguments Details 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 execute these remaining lines in the console.

Usage

1

Arguments

...

Arguments to be passed to source (see below).

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 code is executed using the base function source, to which any arguments are passed (e.g. echo = TRUE causes each expression to be printed before evaluation).

Examples

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

## Run commands only:
rco()

## Check assigned value of a (should be 10):
a

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