Friday, June 3, 2011

read data into R via the clipboard

I tested this on Windows (Excel) and Ubuntu (Gnumeric) and it is a nice little feature which can save a lot of time. If you copy a data table in a spreadsheet into the clipboard you can read the data into R with

> x <- read.delim("clipboard", na.str=".", header=T)

Do not try it with really big tables... ;)


on mac there is something similar, I made a note when we tried it on a mac during a course but i do not remember exactly and can not test it because i do not own a macbook...

> read.table(pipe("pbpaste"))

2 comments :

  1. You can try with my mac book ;-)

    Guess who!

    ReplyDelete
  2. Nice. Other post's suggested writing to the clipboard on linux is problematic*. Thanks to your post i see that at least reading from it is...too easy. Thanks for sharing!

    * http://stackoverflow.com/questions/10959521/how-to-write-to-clipboard-on-ubuntu-linux-in-r

    ReplyDelete