[Rd] accessing windows clipboard from load and save (PR#4999)

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Nov 8 17:03:19 MET 2003

On Sat, 8 Nov 2003, Duncan Murdoch wrote:

> Another special connection (which might exist? I couldn't spot it)
> would be one that read from a character vector, i.e. c('a','b','c')
> would be read as 3 lines of one letter each.  Then something like
>  stringConnection(readClipboard()) 

It's called a textConnection:

> readLines(textConnection(c('a','b','c')))
[1] "a" "b" "c"

The problem here is not with the file("clipboard") connection but with the
documented restriction of load() to suitable connections, including
needing binary mode (which text connections don't have either).

The following *will* work

zz <- file("clipboard", "w")
save(x, ascii=TRUE, file=zz)
zz <- file("clipboard", "r")
readLines(zz, 1)
.Internal(loadFromConn(zz, .GlobalEnv))

so this can be done with existing functions (if one is prepared to do 
5 mins exploration, unlike some unhelpful people).

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-devel mailing list