R 4.2.0: write.table() "clipboard-1024" copies only columns name

650 Views Asked by At

I used write.table(mat, "clipboard-1024", sep="\t", row.names=FALSE) to copy from R to Excel in previous versions. After updating to 4.2.0 it copies columns names only to clipboard. Win 10 64 bit. Any ideas on how to fix it? Try this:

mat = matrix(0, 2, 3)
write.table(mat, "clipboard-1024", sep="\t", row.names=FALSE)
1

There are 1 best solutions below

1
On BEST ANSWER

From Tomas Kalibera (Bugzilla) Thanks for the report and the nicely minimized example. Fixed in R-devel and will be ported to R-patched. The bug is in new clipboard code and affects any code doing subsequent writes to already opened clipboard connection. This is another repro for the same issue:

con <- file("clipboard")
open(con, "w")
cat("A", file=con)
cat("B", file=con)
close(con)
readLines("clipboard") # should be AB but instead A<garbage>

It only affects Windows because R supports writing to clipboard only on Windows.