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

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Feb 18 00:59:56 CET 2005


Ken Knoblauch <knoblauch at lyon.inserm.fr> writes:

> 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. 

I think the "Header" means the first handful of lines (up to 5) used
to determine the file layout.

FWIW, here's what you can do with oocalc and tcltk on Linux:

> library(tcltk)
> read.delim(textConnection(tclvalue(tcl("clipboard","get"))))
  col1 col2
1   12   NA
2   34   56

OK, so it leaves an open connection dangling, but so does your
pipe()... 

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list