Description Usage Arguments Details Value Author(s) See Also Examples
Enhanced control over object type
The default is to read from clipboad into a character vector, and this will always
work.
You can attempt
to convert this to other objects, like matrix
or data.frame
, if
the clipboard contains suitable data (eg multi-line strings with tab's or comma's
separating fields).
We have tested this using vectors, 1 element per line; list, where each line
becomes its own list element, matrix and data.frame, where each line is a row,
each column is tab separated; also a Date class (see examples).
1 2 3 4 |
class |
the class of the object to be created |
sep |
the separator to use if |
ok |
logical: is it OK to be missing a final EOL? |
warn |
logical: warn if the clipboard is missing a final EOL |
header |
logical: if |
If you need finer control when importing to matrix
or data.frame
, we
recommend you use read.table(..., file=pipe("pbpaste"), ...)
.
You can copy & paste actual representations of an R object complete with
attributes & names etc using dput
/dget
. see examples.
a data object from the clipboard, of type class
.
Mark Cowley, 2011-07-22
readLines
, pbcopy
, the “Clipboard” section within ?file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | ## Not run:
pbcopy(letters)
input <- pbpaste()
input <- pbpaste("character")
pbcopy(1:10)
pbpaste()
pbpaste("numeric")
df <- data.frame(a=letters[1:5], b=LETTERS[1:5], c=1:5)
pbcopy(df)
input <- pbpaste("data.frame")
input <- pbpaste("matrix")
input <- pbpaste("list")
input <- pbpaste("Date") # this should fail
pbcopy(Sys.Date())
# structure(15286, class = "Date")
pbpaste() # the class parameter is ignored, since the clipboard already knows its class
pbpaste("character") # the class parameter is ignored, since the clipboard already knows its class
# here's a way to copy the actual object represntation to & from the clipboad
# (great for copying objects between R sessions)
dput(letters, pipe("pbpaste", "w"))
dget(pipe("pbcopy"))
# data.frame
if( require(datasets) ) {
pbcopy(iris, col.names=TRUE)
head(pbpaste("data.frame", header=T))
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# 2 5.1 3.5 1.4 0.2 setosa
# 3 4.9 3 1.4 0.2 setosa
# 4 4.7 3.2 1.3 0.2 setosa
# 5 4.6 3.1 1.5 0.2 setosa
# 6 5 3.6 1.4 0.2 setosa
# 7 5.4 3.9 1.7 0.4 setosa
head(pbpaste("data.frame", header=F))
# V1 V2 V3 V4 V5
# 1 Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# 2 5.1 3.5 1.4 0.2 setosa
# 3 4.9 3 1.4 0.2 setosa
# 4 4.7 3.2 1.3 0.2 setosa
# 5 4.6 3.1 1.5 0.2 setosa
# 6 5 3.6 1.4 0.2 setosa
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.