From murdoch at stats.uwo.ca  Sat Dec  4 01:55:26 2004
From: murdoch at stats.uwo.ca (murdoch@stats.uwo.ca)
Date: Sat Dec  4 01:55:28 2004
Subject: [Rd] write.table inconsistency (PR#7403)
Message-ID: <20041204005526.3C298F18D@slim.kubism.ku.dk>

There's an as.matrix() call in write.table that means the formatting
of numeric columns changes depending on whether there are any
non-numeric columns in the table or not.  For example,

> x <- data.frame(a=1:10,b=1:10)
> write.table(x,sep=',',row.names=F)
"a","b"
1,1
2,2
3,3
4,4
5,5
6,6
7,7
8,8
9,9
10,10
> x <- data.frame(a=1:10,b=as.factor(1:10))
> write.table(x,sep=',',row.names=F)
"a","b"
 1,"1"
 2,"2"
 3,"3"
 4,"4"
 5,"5"
 6,"6"
 7,"7"
 8,"8"
 9,"9"
10,"10"

Notice that column "a" has a leading space in the second example, but
not the first.

Normally this won't matter, but RSQLite uses write.table in the
sqliteWriteTable function, which would cause column "a" above to be
treated as text rather than numeric, and be sorted as text rather than
into numerical order.

Duncan Murdoch


[Rd] write.table inconsistency (PR#7403)
murdoch@stats.uwo.ca