[R] Clipboard under Linux/Unix
(Ted Harding)
Ted.Harding at nessie.mcc.ac.uk
Fri Nov 19 10:49:19 CET 2004
On 19-Nov-04 Philippe Grosjean wrote:
> Hello,
>
> This may be a trivial question, but I don't find the answer
> in R online help. Under Windows, I can copy/paste to the
> clipboard using readClipboard()/writeClipboard(), or something
> like cat(..., file = "clipboard"). Are there equivalent function
> for other platforms?
> Best,
>
> Philippe Grosjean
Hi Philippe,
Leaving aside the situation described by Brian, where the network
is set up to prevent it, normally in Unix/Linux running X windows
you could in certain circumstances (see below) do it transparantly
over the net between machines, as well as within the machine you
are working on, under program control.
Of course there is the usual "block-copy using mouse left button
and paste using mouse middle button" manoeuvre, but -- provided
you have WindowMaker installed (part of GNUstep, the NeXTstep
emulator; you don't need to be running WindowMaker, only to
have the relevant binaries available as /usr/X11R6/bin/wxcopy
and /usr/X11R6/bin/wxpaste) -- then there are also two commands
which put it under program control, especially useful for larger
blocks of text.
1. From 'man wxcopy':
wxcopy(1x) wxcopy(1x)
NAME
wxcopy - copy stdin or file into cutbuffer
SYNOPSIS
wxcopy [options] [filename]
DESCRIPTION
wxcopy copies stdin or filename into the cutbuffer. If no
cutbuffer is specified, the data will be copied into cut-
buffer 0 and the other cutbuffers will be rotated, if pre-
sent. If a cutbuffer is specified, the data is copied
into that cutbuffer, and no rotation of buffers is per-
formed.
2. From 'man wxpaste':
wxpaste(1x) wxpaste(1x)
NAME
wxpaste - output a cutbuffer to stdout
SYNOPSIS
wxpaste [options]
DESCRIPTION
wxpaste outputs the contents of the specified cutbuffer to
stdout. If no cutbuffer is specified, the cutbuffer 0 will
be used as default.
(Read the man pages in full for information on the options, etc.)
Using these two commands, you should be able to write an R function
(using 'system()' function to invoke these commands) which does
what you want; you will probably need to exploit the Unix-type
redirection methods as well, e.g. to redirect stdout from 'wpaste'
as in
wpaste > file.to.paste.into
As a trivial example:
wxcopy < file1
wxpaste > file2
Then file2 will contain a copy of the contents of file1.
To illustrate how it works (as typed in):
-----------------------------------------
wxcopy << EOT
This is something
I want to copy into the cut buffer
and then
paste into the file
"mycopy"
EOT
wxpaste > mycopy
and this gives the contents of the file mycopy:
-----------------------------------------------
cat mycopy
This is something
I want to copy into the cut buffer
and then
paste into the file
"mycopy"
Hoping this helps,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861 [NB: New number!]
Date: 19-Nov-04 Time: 09:49:19
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list