[R-SIG-Mac] R-SIG-Mac] Clipboard

Hans-Joerg Bibiko bibiko at eva.mpg.de
Wed May 16 16:57:22 CEST 2007


some time ago I had the same problem. Unless it isn't solved natively  
I use this hack:

I overwrote the file function in R's start script:

file<-function(description = "", open = "", blocking = TRUE, encoding  
= getOption("encoding")){
	.Internal(file(description, open, blocking, encoding))

By doing so you stay cross-platform. But note it is not UTF-8  
compatible. If one need utf-8 support one could write a bash script  
which writes the clipboard content to a file. Then one could replace  
pipe("clipboard") by system("THEBASH");file("/tmp/foo").

Of course, I know this is really a quirky hack but for me it works  
ALMOST quite well, and I can work with the same scripts on a Mac  
(without X11) or on Linux.
If there are unexpected problems you can easily write: rm(file).


>> Hi there,
>> This command  to use the clipboard as a data source used (pre 2.4?)
>> to work on OS X:
>>  my.data <- read.table(file("clipboard"),header=TRUE)
>>  my.data <- read.table("clipboard", header=TRUE)
>> Now (2.5) the above forms generate an error
>>> Error in open.connection(file, "r") : unable to open connection
>>> In addition: Warning message:
>>> Clipboard cannot be opened or contains no text
>> And instead we have to do:
>> my.data <- read.table(pipe("pbpaste"), header=TRUE)
>> I wonder as this is quite a nice feature, and widely used, if the PC
>> version
>> should not be emulated on the mac (i.e., both the os x terminology
>> "pbpaste"
>> and the generic and user friendly "clipboard" work?
>> It would seem especially valuable as it will help scripts stay
>> cross-platform. The only drawback i can see if that you couldn't  
>> access
>> files called "clipboard" stored in the target directory, but that
>> seems no
>> practical loss.
>> Tim

More information about the R-SIG-Mac mailing list