[R] Easy cut & paste from Excel to R?

Ken Knoblauch knoblauch at lyon.inserm.fr
Thu Feb 17 23:09:24 CET 2005


Here is something quick & dirty for Mac that may be serviceable in
some cases, while awaiting someone with greater understanding of
programming connections than I have currently.

With the following copied to the clipboard from Excell:
H	T	Q	F
1	2	3.3	a
3	5	10.2	b
5	9	11	A

I tried in R:

read.table(pipe("pbpaste"),header=TRUE)
  H T    Q F
1 1 2  3.3 a
2 3 5 10.2 b
3 5 9 11.0 A
Warning message: 
incomplete final line found by readTableHeader on `pbpaste' 
> str(read.table(pipe("pbpaste"),header=TRUE))
`data.frame':	3 obs. of  4 variables:
 $ H: int  1 3 5
 $ T: int  2 5 9
 $ Q: num  3.3 10.2 11
 $ F: Factor w/ 3 levels "A","a","b": 2 3 1
Warning message: 
incomplete final line found by readTableHeader on `pbpaste'

I haven't been able to track down readTableHeader yet.  The warning
occurs even without headers in the data. 


Quoting Prof Brian Ripley <ripley at stats.ox.ac.uk>:

> On Thu, 17 Feb 2005, Uwe Ligges wrote:
> 
> > Ken Knoblauch wrote:
> >
> >> I tried the interesting suggestion below, discussed in several postings 
> >> yesterday on the help-list, on my Mac (0S 10.3.7) but could not get it
> to
> >> work, as shown in the tests indicated below.
> >> 
> >> 
> >>>>  read.table(file("clipboard"), sep="\t", dec=",")
> >
> > Connections to the clipboard are only available on Windows.
> 
> Ken is of course welcome to contribute them for MacOS X (or indeed for
> X11).
> People do take for granted the work the developers do to provide such 
> things ....
> 
> -- 
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
> 



____________________
Ken Knoblauch
Inserm U 371
Cerveau et Vision
18 avenue du Doyen Lepine
69675 Bron cedex
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: 06 84 10 64 10




More information about the R-help mailing list