Solution for error message in R for pasting Excel data from clipboard (pipe(‘pbpaste’) )

One of the quickest ways in R to get data into it is to copy to the clipboard then paste it into a variable.

This can be done in Windows by

read.table("clipboard", header=T)

The exact same function can be done on a MAC computer with

read.table(pipe("pbpaste"), header=T)

However, in the MAC a red warning message appears like this

Screenshot 2018-02-14 19.09.54

What seems to be happening is that R seems to read the clipboard with a missing closing line to the table. This also happens with files. Although the warning message does not seem to affect the data and can be ignored, it is annoying. So if you really want to see this message disappear, you can:

  1. copy the data from MS Excel
  2. paste into then copy the data from MS Word
  3. paste into R with read.table(pipe("pbpaste"), header=T)

This seems to do the trick when nothing else seems to work. While this is not the most elegant and ideal solution, it is a solution. Enjoy.

Clipboard hack for R in MAC

When I first started using the statistical software R for statistics I had started on a Windows computer. For here the copying and pasting function is

read.table("clipboard", header=T)

The exact same function on a MAC computer is

read.table(pipe("pbpaste"), header=T)

Simple as that. I’d someone had told me this much earlier.