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

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?)


I like to use only the memory I need. So I let the object.size() function figure out what I need. In addition, I usually like to source a function that I like to use frequently.

df1 <- data.frame(x=runif(10000))
write.excel <- function(x,row.names=FALSE,col.names=TRUE,...) {
  write.table(x,file = paste0("clipboard-", object.size(x)),sep="\t",row.names=row.names,col.names=col.names,...)
}

write.excel(df1, FALSE, TRUE)

It would probably be prudent to check the object.size is smaller than the memory.size. And let this thing fail if necessary.

Hope this helps.

Tags:

R