Code to import data from a Stack overflow query into R

Maybe textConnection() is what you want here:

R> zz <- read.table(textConnection("a  b   c
1 11 foo
2 12 bar
3 13 baz
4 14 bar
5 15 foo"), header=TRUE)
R> zz
  a  b   c
1 1 11 foo
2 2 12 bar
3 3 13 baz
4 4 14 bar
5 5 15 foo
R> 

It allows you to treat the text as a “connection” from which to read. You can also just copy and paste, but access from the clipboard is more dependent on the operating system and hence less portable.

Leave a Comment