Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve "clipboard buffer is full and output lost" error in R running in Windows?

Tags:

r

I am trying to copy some data directly from R to the clipboard, in my Windows machine. I found in some sites that using file="clipboard" would work. And it does, but for very small datasets.

For example:

If I copy a small dataset (100 obs), it works smoothly.

df1 <- data.frame(x=runif(100)) write.table(df1, file="clipboard", sep="\t", col.names=NA) 

But if I increase the observations to 10,000, it fails:

df1 <- data.frame(x=runif(10000)) write.table(df1, file="clipboard", sep="\t", col.names=NA) 

The error is:

Warning message: In .External2(C_writetable, x, file, nrow(x), p, r

Any workaround to this?

like image 977
Hernando Casas Avatar asked Aug 16 '15 12:08

Hernando Casas


1 Answers

If you type ?connections you will find your answer.

This is the relevant part:

"When writing to the clipboard, the output is copied to the clipboard only when the connection is closed or flushed. There is a 32Kb limit on the text to be written to the clipboard. This can be raised by using e.g. file("clipboard-128") to give 128Kb."

So, the solution is pretty straigthforward:

df1 <- data.frame(x=runif(10000)) write.table(df1, file="clipboard-16384", sep="\t", col.names=NA) 

Note that the number of Kb is just an example, so you can change it as you need (I put 2^14 that should be more than enough for your data set, but you can increase it even more. Not sure which is the hard limit, though. Maybe physical memory?)

like image 80
elikesprogramming Avatar answered Sep 19 '22 12:09

elikesprogramming