Discussion:
[R] Easy cut & paste from Excel to R?
Werner Wernersen
2005-02-16 08:59:14 UTC
Permalink
Hi!

Is it possible to easily cut & paste data from an
Excel spreadsheet to
an R edit( ) grid or to variable?
It seems that R cannot handle the cell delimiters
Excel hands over.

Regards,
Werner
Uwe Ligges
2005-02-16 09:14:52 UTC
Permalink
Post by Werner Wernersen
Hi!
Is it possible to easily cut & paste data from an
Excel spreadsheet to
an R edit( ) grid or to variable?
It seems that R cannot handle the cell delimiters
Excel hands over.
Regards,
Werner
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
copy in Excel and say in R:
read.table(file("clipboard"))

Uwe Ligges
Peter Dalgaard
2005-02-16 10:18:53 UTC
Permalink
Post by Uwe Ligges
Post by Werner Wernersen
Hi!
Is it possible to easily cut & paste data from an
Excel spreadsheet to an R edit( ) grid or to variable?
It seems that R cannot handle the cell delimiters
Excel hands over.
Regards,
Werner
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
read.table(file("clipboard"))
Er, doesn't that want to be read.delim (or read.delim2 in
"comma-locales")? Plain read.table() could cause some grief if there
are empty cells.
--
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
Uwe Ligges
2005-02-16 10:42:15 UTC
Permalink
Post by Peter Dalgaard
Post by Uwe Ligges
Post by Werner Wernersen
Hi!
Is it possible to easily cut & paste data from an
Excel spreadsheet to an R edit( ) grid or to variable?
It seems that R cannot handle the cell delimiters
Excel hands over.
Regards,
Werner
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
read.table(file("clipboard"))
Er, doesn't that want to be read.delim (or read.delim2 in
"comma-locales")? Plain read.table() could cause some grief if there
are empty cells.
Well, yes, some arguments twisting might be required as for my german
locales / german version of Excel the following works even for empty
cells and real valued entries:

read.table(file("clipboard"), sep="\t", dec=",")

V1 V2 V3
1 1.2 NA 2.3
2 3.4 4.5 5.6


Uwe Ligges
Peter Dalgaard
2005-02-16 10:42:38 UTC
Permalink
Post by Uwe Ligges
Well, yes, some arguments twisting might be required as for my german
locales / german version of Excel the following works even for empty
read.table(file("clipboard"), sep="\t", dec=",")
V1 V2 V3
1 1.2 NA 2.3
2 3.4 4.5 5.6
...which is of course the same as

read.delim2(file("clipboard"), header=FALSE)

except for possible variations in the fill and quote settings. (What
happens if you have empty cells in the last columns, or cells with
the text "Don't do this"?)
--
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
Uwe Ligges
2005-02-16 10:54:55 UTC
Permalink
Post by Peter Dalgaard
Post by Uwe Ligges
Well, yes, some arguments twisting might be required as for my german
locales / german version of Excel the following works even for empty
read.table(file("clipboard"), sep="\t", dec=",")
V1 V2 V3
1 1.2 NA 2.3
2 3.4 4.5 5.6
...which is of course the same as
read.delim2(file("clipboard"), header=FALSE)
except for possible variations in the fill and quote settings. (What
happens if you have empty cells in the last columns, or cells with
the text "Don't do this"?)
Yes, you are right, thanks!

Uwe
Gabor Grothendieck
2005-02-16 14:46:36 UTC
Permalink
Peter Dalgaard <p.dalgaard <at> biostat.ku.dk> writes:

:
: Uwe Ligges <ligges <at> statistik.uni-dortmund.de> writes:
:
: > Well, yes, some arguments twisting might be required as for my german
: > locales / german version of Excel the following works even for empty
: > cells and real valued entries:
: >
: > read.table(file("clipboard"), sep="\t", dec=",")
: >
: > V1 V2 V3
: > 1 1.2 NA 2.3
: > 2 3.4 4.5 5.6
:
: ...which is of course the same as
:
: read.delim2(file("clipboard"), header=FALSE)

which is the same as

read.delim2("clipboard", header = FALSE)

:
: except for possible variations in the fill and quote settings. (What
: happens if you have empty cells in the last columns, or cells with
: the text "Don't do this"?)
:
Nick Drew
2005-02-16 13:08:36 UTC
Permalink
I've had good luck with the scan() function when I
want to get a few numbers from Excel into R quickly to
use it as a calculator. CAVEAT: you have to have the
numbers you want to copy in a column not a row in
Excel. For example:

In Excel your data are in a column as follows:
Col A
1
2
3

Then copy the 3 cells (e.g. 1, 2,3) in Excel and open
data <- scan()
Then Paste using Ctrl-V. Hit the Enter key. You know
have an object called "data" that you can use and
manipulate in R.

I've taken this even further by creating an R function
that will take a column of numbers from Excel and then
scan() them into R, create a matrix, and then perform
a Chi-square test. Let me know if you'd like to know
more. I'm a beginner and if I can do so can you!!

~Nick
Werner Wernersen
2005-02-16 17:20:43 UTC
Permalink
Thank you all very much for the answers!
The read.table / read.delim2 commands are exactly what
I was looking for to get
a couple of numbers or a little matrix quickly into R
without creating an extra
text file every time.

And it works the other way around as well:
write.table(x, file("clipboard"), sep="\t")
Fantastic!

Thanks again,
Werner
Post by Nick Drew
I've had good luck with the scan() function when I
want to get a few numbers from Excel into R quickly
to
Post by Nick Drew
use it as a calculator. CAVEAT: you have to have the
numbers you want to copy in a column not a row in
Col A
1
2
3
Then copy the 3 cells (e.g. 1, 2,3) in Excel and
open
Post by Nick Drew
data <- scan()
Then Paste using Ctrl-V. Hit the Enter key. You know
have an object called "data" that you can use and
manipulate in R.
I've taken this even further by creating an R
function
Post by Nick Drew
that will take a column of numbers from Excel and
then
Post by Nick Drew
scan() them into R, create a matrix, and then
perform
Post by Nick Drew
a Chi-square test. Let me know if you'd like to know
more. I'm a beginner and if I can do so can you!!
~Nick
__________________________________
Jose Quesada
2005-09-29 11:12:00 UTC
Permalink
Sorry to revive and old topic, but writing to the clipboard seems to
have a problem for me: column names are ignored. Example:

# ~~~~~~~~~~~~~~~~~~~~~~~
# write.clipboard
# ~~~~~~~~~~~~~~~~~~~~~~~
write.clipboard = function(obj) {
write.table(obj, file("clipboard"), sep="\t", row.names=F, col.names=T)
}

a= matrix(1:4,2,2)
colnames(a) = c("a", "b")

write.clipboard(a)
a = as.data.frame(a)
write.clipboard(a)

both attempts will paste the date without column names.
Any idea why?

Thanks,
-Jose
Post by Werner Wernersen
Thank you all very much for the answers!
The read.table / read.delim2 commands are exactly what
I was looking for to get
a couple of numbers or a little matrix quickly into R
without creating an extra
text file every time.
write.table(x, file("clipboard"), sep="\t")
Fantastic!
Thanks again,
Werner
Post by Nick Drew
I've had good luck with the scan() function when I
want to get a few numbers from Excel into R quickly
to
Post by Nick Drew
use it as a calculator. CAVEAT: you have to have the
numbers you want to copy in a column not a row in
Col A
1
2
3
Then copy the 3 cells (e.g. 1, 2,3) in Excel and
open
Post by Nick Drew
data <- scan()
Then Paste using Ctrl-V. Hit the Enter key. You know
have an object called "data" that you can use and
manipulate in R.
I've taken this even further by creating an R
function
Post by Nick Drew
that will take a column of numbers from Excel and
then
Post by Nick Drew
scan() them into R, create a matrix, and then
perform
Post by Nick Drew
a Chi-square test. Let me know if you'd like to know
more. I'm a beginner and if I can do so can you!!
~Nick
__________________________________
Do you Yahoo!?
http://promotions.yahoo.com/new_mail
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
--
Jose Quesada, PhD.

j.quesada at warwick.ac.uk ESRC Postdoctoral Fellow
http://lsa.colorado.edu/~quesadaj Dept. of PSychology
http://www.andrew.cmu.edu/~jquesada University of Warwick
office H114 Phone: +44 024 765 23 759
Coventry, UK
roger bos
2005-09-29 12:00:00 UTC
Permalink
An embedded and charset-unspecified text was scrubbed...
Name: not available
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20050929/10514053/attachment.pl
Gabor Grothendieck
2005-09-29 13:01:48 UTC
Permalink
See:

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/26922.html
Post by Jose Quesada
Sorry to revive and old topic, but writing to the clipboard seems to
# ~~~~~~~~~~~~~~~~~~~~~~~
# write.clipboard
# ~~~~~~~~~~~~~~~~~~~~~~~
write.clipboard = function(obj) {
write.table(obj, file("clipboard"), sep="\t", row.names=F, col.names=T)
}
a= matrix(1:4,2,2)
colnames(a) = c("a", "b")
write.clipboard(a)
a = as.data.frame(a)
write.clipboard(a)
both attempts will paste the date without column names.
Any idea why?
Thanks,
-Jose
Post by Werner Wernersen
Thank you all very much for the answers!
The read.table / read.delim2 commands are exactly what
I was looking for to get
a couple of numbers or a little matrix quickly into R
without creating an extra
text file every time.
write.table(x, file("clipboard"), sep="\t")
Fantastic!
Thanks again,
Werner
Post by Nick Drew
I've had good luck with the scan() function when I
want to get a few numbers from Excel into R quickly
to
Post by Nick Drew
use it as a calculator. CAVEAT: you have to have the
numbers you want to copy in a column not a row in
Col A
1
2
3
Then copy the 3 cells (e.g. 1, 2,3) in Excel and
open
Post by Nick Drew
data <- scan()
Then Paste using Ctrl-V. Hit the Enter key. You know
have an object called "data" that you can use and
manipulate in R.
I've taken this even further by creating an R
function
Post by Nick Drew
that will take a column of numbers from Excel and
then
Post by Nick Drew
scan() them into R, create a matrix, and then
perform
Post by Nick Drew
a Chi-square test. Let me know if you'd like to know
more. I'm a beginner and if I can do so can you!!
~Nick
__________________________________
Do you Yahoo!?
http://promotions.yahoo.com/new_mail
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
--
Jose Quesada, PhD.
j.quesada at warwick.ac.uk ESRC Postdoctoral Fellow
http://lsa.colorado.edu/~quesadaj Dept. of PSychology
http://www.andrew.cmu.edu/~jquesada University of Warwick
office H114 Phone: +44 024 765 23 759
Coventry, UK
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Petr Pikal
2005-09-29 15:29:55 UTC
Permalink
Hi

Works for me.

write.excel <- function (tab, ...) write.table(tab, "clipboard", sep
= "\t", row.names = F)

write.excel(a)

from your example shows in Excel after ctrl-V as a table with names.

HTH

Petr





On 29 Sep 2005 at 12:12, Jose Quesada wrote:

Date sent: Thu, 29 Sep 2005 12:12:00 +0100
From: Jose Quesada <quesada at gmail.com>
To: Werner Wernersen <pensterfuzzer at yahoo.de>
Copies to: r-help at stat.math.ethz.ch
Subject: Re: [R] Easy cut & paste from Excel to R?
Send reply to: Jose Quesada <quesada at gmail.com>
<mailto:r-help-request at stat.math.ethz.ch?subject=unsubscribe>
<mailto:r-help-request at stat.math.ethz.ch?subject=subscribe>
Post by Jose Quesada
Sorry to revive and old topic, but writing to the clipboard seems to
# ~~~~~~~~~~~~~~~~~~~~~~~
# write.clipboard
# ~~~~~~~~~~~~~~~~~~~~~~~
write.clipboard = function(obj) {
write.table(obj, file("clipboard"), sep="\t", row.names=F,
col.names=T)
}
a= matrix(1:4,2,2)
colnames(a) = c("a", "b")
write.clipboard(a)
a = as.data.frame(a)
write.clipboard(a)
both attempts will paste the date without column names.
Any idea why?
Thanks,
-Jose
Post by Werner Wernersen
Thank you all very much for the answers!
The read.table / read.delim2 commands are exactly what
I was looking for to get
a couple of numbers or a little matrix quickly into R
without creating an extra
text file every time.
write.table(x, file("clipboard"), sep="\t")
Fantastic!
Thanks again,
Werner
Post by Nick Drew
I've had good luck with the scan() function when I
want to get a few numbers from Excel into R quickly
to
Post by Nick Drew
use it as a calculator. CAVEAT: you have to have the
numbers you want to copy in a column not a row in
Col A
1
2
3
Then copy the 3 cells (e.g. 1, 2,3) in Excel and
open
Post by Nick Drew
data <- scan()
Then Paste using Ctrl-V. Hit the Enter key. You know
have an object called "data" that you can use and
manipulate in R.
I've taken this even further by creating an R
function
Post by Nick Drew
that will take a column of numbers from Excel and
then
Post by Nick Drew
scan() them into R, create a matrix, and then
perform
Post by Nick Drew
a Chi-square test. Let me know if you'd like to know
more. I'm a beginner and if I can do so can you!!
~Nick
__________________________________
Do you Yahoo!?
http://promotions.yahoo.com/new_mail
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
--
Jose Quesada, PhD.
j.quesada at warwick.ac.uk ESRC Postdoctoral Fellow
http://lsa.colorado.edu/~quesadaj Dept. of PSychology
http://www.andrew.cmu.edu/~jquesada University of Warwick
office H114 Phone: +44 024 765 23 759
Coventry, UK
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
Petr Pikal
petr.pikal at precheza.cz
roger bos
2005-09-30 12:48:08 UTC
Permalink
An embedded and charset-unspecified text was scrubbed...
Name: not available
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20050930/6b3766b2/attachment.pl
Ken Knoblauch
2005-02-17 13:54:46 UTC
Permalink
Hi,

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.
Post by Uwe Ligges
read.table(file("clipboard"), sep="\t", dec=",")
If it is obvious (even, if not), can someone tell me what I am doing wrong?
Do I need to perform an additional operation to open "clipboard", or is this
option not available on Mac? I did not find any special discussion of this in
the FAQ nor searching under "clipboard" in the archives. Thank you, in
advance, for any enlightenment.

data.frame(matrix(rnorm(12),ncol=3))
X1 X2 X3
1 0.4276964 -0.49584891 0.02150469
2 -0.8323586 -0.40120649 -1.90733346
3 -0.8954563 -1.33195844 -1.28261484
4 0.4772382 -0.03703087 0.46719156
#At this point, I block-marked the printed output and apple-C'd it into the
clipboard.
#I then checked the clipboard to verify that the data was indeed copied there.
read.table("clipboard")
Error in file(file, "r") : unable to open connection
In addition: Warning message:
cannot open file `clipboard'
read.table(file("clipboard"))
Error in open.connection(file, "r") : unable to open connection
In addition: Warning message:
cannot open file `clipboard'
read.table(file("clipboard","r"))
Error in file("clipboard", "r") : unable to open connection
In addition: Warning message:
cannot open file `clipboard'
read.table(file("clipboard","r"),header=TRUE)
Error in file("clipboard", "r") : unable to open connection
In addition: Warning message:
cannot open file `clipboard'
read.delim(file("clipboard","r"),header=TRUE)
Error in file("clipboard", "r") : unable to open connection
In addition: Warning message:
cannot open file `clipboard'
file("clipboard")
description class mode text opened can read
"clipboard" "file" "r" "text" "closed" "yes"
can write
"yes"
file("clipboard","r")
Error in file("clipboard", "r") : unable to open connection
In addition: Warning message:
cannot open file `clipboard'

platform powerpc-apple-darwin6.8
arch powerpc
os darwin6.8
system powerpc, darwin6.8
status
major 2
minor 0.1
year 2004
month 11
day 15
language R

____________________
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
Uwe Ligges
2005-02-17 15:19:40 UTC
Permalink
Post by Ken Knoblauch
Hi,
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.
Post by Uwe Ligges
read.table(file("clipboard"), sep="\t", dec=",")
Connections to the clipboard are only available on Windows.

Uwe Ligges
Post by Ken Knoblauch
If it is obvious (even, if not), can someone tell me what I am doing wrong?
Do I need to perform an additional operation to open "clipboard", or is this
option not available on Mac? I did not find any special discussion of this in
the FAQ nor searching under "clipboard" in the archives. Thank you, in
advance, for any enlightenment.
data.frame(matrix(rnorm(12),ncol=3))
X1 X2 X3
1 0.4276964 -0.49584891 0.02150469
2 -0.8323586 -0.40120649 -1.90733346
3 -0.8954563 -1.33195844 -1.28261484
4 0.4772382 -0.03703087 0.46719156
#At this point, I block-marked the printed output and apple-C'd it into the
clipboard.
#I then checked the clipboard to verify that the data was indeed copied there.
read.table("clipboard")
Error in file(file, "r") : unable to open connection
cannot open file `clipboard'
read.table(file("clipboard"))
Error in open.connection(file, "r") : unable to open connection
cannot open file `clipboard'
read.table(file("clipboard","r"))
Error in file("clipboard", "r") : unable to open connection
cannot open file `clipboard'
read.table(file("clipboard","r"),header=TRUE)
Error in file("clipboard", "r") : unable to open connection
cannot open file `clipboard'
read.delim(file("clipboard","r"),header=TRUE)
Error in file("clipboard", "r") : unable to open connection
cannot open file `clipboard'
file("clipboard")
description class mode text opened can read
"clipboard" "file" "r" "text" "closed" "yes"
can write
"yes"
file("clipboard","r")
Error in file("clipboard", "r") : unable to open connection
cannot open file `clipboard'
platform powerpc-apple-darwin6.8
arch powerpc
os darwin6.8
system powerpc, darwin6.8
status
major 2
minor 0.1
year 2004
month 11
day 15
language R
____________________
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
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Prof Brian Ripley
2005-02-17 17:22:58 UTC
Permalink
Post by Uwe Ligges
Post by Ken Knoblauch
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.
Post by Uwe Ligges
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
2005-02-17 22:09:24 UTC
Permalink
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.
Post by Uwe Ligges
Post by Ken Knoblauch
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
Post by Uwe Ligges
Post by Ken Knoblauch
work, as shown in the tests indicated below.
Post by Uwe Ligges
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
Peter Dalgaard
2005-02-17 23:59:56 UTC
Permalink
Post by Ken Knoblauch
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.
H T Q F
1 2 3.3 a
3 5 10.2 b
5 9 11 A
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
incomplete final line found by readTableHeader on `pbpaste'
str(read.table(pipe("pbpaste"),header=TRUE))
$ 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
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.
Post by Ken Knoblauch
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
Bernhard Bruemmer
2005-02-18 08:24:33 UTC
Permalink
Post by Peter Dalgaard
Post by Ken Knoblauch
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
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
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.
Post by Ken Knoblauch
library(tcltk)
read.delim(textConnection(tclvalue(tcl("clipboard","get"))))
col1 col2 1 12 NA 2 34 56
An alternative solution for X11 is provided by the utility program xclip
(http://people.debian.org/~kims/xclip). After selecting the desired
data in, say, oocalc, the data can be
read using the appropriate read.table variant:

data <- read.delim(pipe("xclip -o"))

showConnections() does not reveal any problems after this command.
--
Dr. Bernhard Br?mmer
Institute of Agricultural Economics
Georg-August-Universit?t G?ttingen
Platz der G?ttinger Sieben 5
37073 G?ttingen
Germany
Tel +49 (0)551 394811 Fax +49 (0)551 399866
Don MacQueen
2005-02-18 17:03:47 UTC
Permalink
I tried Ken's suggestion
read.table(pipe("pbpaste"),header=TRUE)
on my Mac OS X system and it worked *without* generating any warning message.

If my experience represents the norm, and Ken's is the exception, it
is so simple that no further contribution to R is needed, I would
say. Thank you, Ken.

The method can also be to go the other way, using pbcopy instead of pbpaste.
test <- data.frame(a=1:3,b=letters[1:3])
zz <- pipe('pbcopy','w')
write.table(test,file=zz,sep='\t',row.names=FALSE)
close(zz)
Then in Excel (or any other Mac-native application) use the Paste command.


In the past I would get the warning message that Ken reports when I
used read.delim() on tab-delimited files
created using Excel's "Save as tab delimited" option. Excel does not
put a newline at the
end of the last line, and as a result R would generate that error
message. Excel still does not.
However, R now reads such files correctly, without generating the
warning message.

pbpaste and pbcopy are included in the OS as distributed by Apple

[163]% which pbpaste
/usr/bin/pbpaste

(though perhaps only if one of the optional developer-related
packages has been installed)
so these methods should be available to all Mac users of R, without
any extra work on their part
(other than learning about them, that is).
bah <- read.table(pipe('pbpaste'),header=TRUE)
dim(bah)
[1] 21 5
showConnections(all=TRUE)
description class mode text isopen can read can write
0 "stdin" "terminal" "r" "text" "opened" "yes" "no"
1 "stdout" "terminal" "w" "text" "opened" "no" "yes"
2 "stderr" "terminal" "w" "text" "opened" "no" "yes"
version
_
platform powerpc-apple-darwin6.8.5
arch powerpc
os darwin6.8.5
system powerpc, darwin6.8.5
status
major 2
minor 0.1
year 2004
month 11
day 15
language R

Mac OS 10.3.8

Excel 2004, version 11.1 (040909)

-Don
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.
H T Q F
1 2 3.3 a
3 5 10.2 b
5 9 11 A
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
incomplete final line found by readTableHeader on `pbpaste'
str(read.table(pipe("pbpaste"),header=TRUE))
$ 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
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.
Post by Uwe Ligges
Post by Ken Knoblauch
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
Post by Uwe Ligges
Post by Ken Knoblauch
work, as shown in the tests indicated below.
Post by Uwe Ligges
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
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
Peter Dalgaard
2005-02-18 17:31:34 UTC
Permalink
Post by Don MacQueen
I tried Ken's suggestion
read.table(pipe("pbpaste"),header=TRUE)
on my Mac OS X system and it worked *without* generating any warning message.
If my experience represents the norm, and Ken's is the exception, it
is so simple that no further contribution to R is needed, I would say.
Thank you, Ken.
My conjecture is that it only happens when there are fewer than 5 data
lines.

We still need to sort out X11. Too bad that the xclip program isn't
ubiquitous.
--
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
Bernhard Bruemmer
2005-02-21 08:57:49 UTC
Permalink
Post by Peter Dalgaard
I tried Ken's suggestion read.table(pipe("pbpaste"),header=TRUE) on
my Mac OS X system and it worked *without* generating any warning
message.
If my experience represents the norm, and Ken's is the exception, it
is so simple that no further contribution to R is needed, I would
say. Thank you, Ken.
My conjecture is that it only happens when there are fewer than 5 data
lines.
We still need to sort out X11. Too bad that the xclip program isn't
ubiquitous.
Does Perl qualify as ubiquitous? If so, the piped xclip call can be
substituted for by the following:

data <- read.delim(pipe("perl -MTk -e 'print MainWindow->new->SelectionGet'"))

Works fine under Linux.

HTH, Bernhard
Prof Brian Ripley
2005-02-21 09:20:46 UTC
Permalink
Post by Bernhard Bruemmer
Post by Peter Dalgaard
I tried Ken's suggestion read.table(pipe("pbpaste"),header=TRUE) on
my Mac OS X system and it worked *without* generating any warning
message.
If my experience represents the norm, and Ken's is the exception, it
is so simple that no further contribution to R is needed, I would
say. Thank you, Ken.
My conjecture is that it only happens when there are fewer than 5 data
lines.
We still need to sort out X11. Too bad that the xclip program isn't
ubiquitous.
Does Perl qualify as ubiquitous?
It is specifically not required for R at runtime: see the `Writing R
Extensions' manual.
Post by Bernhard Bruemmer
If so, the piped xclip call can be
data <- read.delim(pipe("perl -MTk -e 'print MainWindow->new->SelectionGet'"))
Works fine under Linux.
HTH, Bernhard
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
--
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
Prof Brian Ripley
2005-02-23 08:55:52 UTC
Permalink
Post by Peter Dalgaard
Post by Don MacQueen
I tried Ken's suggestion
read.table(pipe("pbpaste"),header=TRUE)
on my Mac OS X system and it worked *without* generating any warning message.
If my experience represents the norm, and Ken's is the exception, it
is so simple that no further contribution to R is needed, I would say.
Thank you, Ken.
My conjecture is that it only happens when there are fewer than 5 data
lines.
We still need to sort out X11. Too bad that the xclip program isn't
ubiquitous.
The read side in X11 is not too hard, and R-devel now has read from the
primary selection via file("clipboard"). (I may change that name and
allow reading from other selections later: I just made small changes to
the Windows code.)

Xlib doesn't it seems really have a clipboard, and so it is much harder to
act as the provider of the primary selection (you need to respond to X11
events) -- xclip forks to do so.

BTW, xclip is at http://people.debian.org/~kims/xclip/ and seems no longer
under active development (last change 18 months ago).
--
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
2005-02-18 16:44:26 UTC
Permalink
In fact, I noticed today that when I copied from an Excell spreadsheet,
rather than just putting some text in a file, that it worked as you
say.

I also downloaded xclip and compiled it, which works just fine
on the Mac, and this mechanisms seems to work the same way as
pbpaste, in terms of generating or not warnings under the same
circumstances. xclip has slightly different options than pbpaste
(e.g., you can access 3 different pasteboards) and it would seem to cover
the X11 situation. So, it represents a solution that is
slightly more general, as applying to both Mac and linux.
Post by Don MacQueen
I tried Ken's suggestion
read.table(pipe("pbpaste"),header=TRUE)
on my Mac OS X system and it worked *without* generating any warning
message.
If my experience represents the norm, and Ken's is the exception, it
is so simple that no further contribution to R is needed, I would
say. Thank you, Ken.
The method can also be to go the other way, using pbcopy instead of
pbpaste.
test <- data.frame(a=1:3,b=letters[1:3])
zz <- pipe('pbcopy','w')
write.table(test,file=zz,sep='\t',row.names=FALSE)
close(zz)
Then in Excel (or any other Mac-native application) use the Paste command.
In the past I would get the warning message that Ken reports when I
used read.delim() on tab-delimited files
created using Excel's "Save as tab delimited" option. Excel does not
put a newline at the
end of the last line, and as a result R would generate that error
message. Excel still does not.
However, R now reads such files correctly, without generating the
warning message.
pbpaste and pbcopy are included in the OS as distributed by Apple
[163]% which pbpaste
/usr/bin/pbpaste
(though perhaps only if one of the optional developer-related
packages has been installed)
so these methods should be available to all Mac users of R, without
any extra work on their part
(other than learning about them, that is).
bah <- read.table(pipe('pbpaste'),header=TRUE)
dim(bah)
[1] 21 5
showConnections(all=TRUE)
description class mode text isopen can read can write
0 "stdin" "terminal" "r" "text" "opened" "yes" "no"
1 "stdout" "terminal" "w" "text" "opened" "no" "yes"
2 "stderr" "terminal" "w" "text" "opened" "no" "yes"
version
_
platform powerpc-apple-darwin6.8.5
arch powerpc
os darwin6.8.5
system powerpc, darwin6.8.5
status
major 2
minor 0.1
year 2004
month 11
day 15
language R
Mac OS 10.3.8
Excel 2004, version 11.1 (040909)
-Don
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.
H T Q F
1 2 3.3 a
3 5 10.2 b
5 9 11 A
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
incomplete final line found by readTableHeader on `pbpaste'
str(read.table(pipe("pbpaste"),header=TRUE))
$ 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
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.
Post by Uwe Ligges
Post by Ken Knoblauch
I tried the interesting suggestion below, discussed in several
postings
Post by Uwe Ligges
Post by Ken Knoblauch
yesterday on the help-list, on my Mac (0S 10.3.7) but could not get
it
to
Post by Uwe Ligges
Post by Ken Knoblauch
work, as shown in the tests indicated below.
Post by Uwe Ligges
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
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
--------------------------------------
____________________
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
Ken Knoblauch
2005-02-18 20:48:31 UTC
Permalink
You are right. The warning disappears at exactly five lines of data,
not including the header.

Well, how often do you come across a data.frame with less than 5 rows
and too many covariates to enter by hand?

kk
Post by Don MacQueen
Post by Don MacQueen
I tried Ken's suggestion
read.table(pipe("pbpaste"),header=TRUE)
on my Mac OS X system and it worked *without* generating any warning
message.
My conjecture is that it only happens when there are fewer than 5 data
lines.
We still need to sort out X11. Too bad that the xclip program isn't
ubiquitous.
--
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
____________________
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
Continue reading on narkive:
Loading...