Full_Name: Gabor Grothendieck
Version: 1.7.1
OS: Windows 2000
Submission from: (NULL) (207.35.143.81)
save(x,ascii=TRUE,file("clipboard"))
works but
load(file("clipboard"))
does not.
Even better would be if
save(x,ascii=TRUE,"clipboard")
and
load("clipboard")
worked as that would provide consistency with read.table("clipboard")
accessing windows clipboard from load and save (PR#4999)
5 messages · Gabor Grothendieck, Brian Ripley, Duncan Murdoch
On Sat, 8 Nov 2003 15:21:48 +0100 (CET), you wrote:
Full_Name: Gabor Grothendieck
Version: 1.7.1
OS: Windows 2000
Submission from: (NULL) (207.35.143.81)
save(x,ascii=TRUE,file("clipboard"))
works but
load(file("clipboard"))
does not.
This is a documented limitation of the clipboard connection (which is write-only), not a bug. Yes, it would be nice if all clipboard functions were supported, but they're not.
Even better would be if
save(x,ascii=TRUE,"clipboard")
and
load("clipboard")
worked as that would provide consistency with read.table("clipboard")
Is this documented somewhere? I didn't know about it (but it does
work).
Personally, I'd rather have a connection created by a function named
clipboard(); it looks kludgy to interpret some filenames as magic
values. Then your examples would be
save(x,ascii=TRUE,file=clipboard('w'))
load(clipboard())
read.table(clipboard())
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())
would be one way to implement clipboard().
Duncan Murdoch
Yet another report of a non-bug!
First, your example of the use of save() does not work. That *is* a bug.
Second, please RTFM. help(load) says
'load' can load R objects saved in the current or any earlier
format. It can read a compressed file (see 'save') directly from
a file or from a suitable connection.
^^^^^^^^
and nothing says a clipboard is a suitable connection.
If you really want to make a positive contribution you could work out what
changes are necessary to make a clipboard a suitable connection and supply
a patch against the current sources (not an obselete version of R). Hints:
load expects to be able to open a connection in binary mode, and to wrap
it in a decompression wrapper.
On Sat, 8 Nov 2003 ggrothendieck@myway.com wrote:
Full_Name: Gabor Grothendieck
Version: 1.7.1
OS: Windows 2000
Submission from: (NULL) (207.35.143.81)
save(x,ascii=TRUE,file("clipboard"))
works but
load(file("clipboard"))
does not.
Even better would be if
save(x,ascii=TRUE,"clipboard")
and
load("clipboard")
worked as that would provide consistency with read.table("clipboard")
______________________________________________ R-devel@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-devel
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
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
On Sat, 8 Nov 2003 16:03:19 +0000 (GMT), you wrote:
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).
I was misled by a typo in the man page for file, where it says:
Under Windows, 'file' can also be used with 'description =
"clipboard"' in mode '"w"' and '"w"' only.
Presumably that should be "in modes '"r"' and '"w"'."
In the ?load page, I see the words "suitable connection", but I don't
see any mention of binary access being required. Is that documented
somewhere?
I guess it comes from the use of gzcon in load. Couldn't the
restriction be removed by having gzcon treat any text mode connection
as uncompressed?
Duncan Murdoch