From ripley at stats.ox.ac.uk  Sat Nov  8 17:03:19 2003
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Sat Nov  8 17:02:46 2003
Subject: [Rd] accessing windows clipboard from load and save (PR#4999)
In-Reply-To: <3s2qqv8oa86pn0ltgd7sufqvlep8copa2f@4ax.com>
Message-ID: <Pine.LNX.4.44.0311081551160.8090-100000@gannet.stats>

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)
close(zz)
zz <- file("clipboard", "r")
readLines(zz, 1)
.Internal(loadFromConn(zz, .GlobalEnv))
close(zz)

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@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


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