From dmurdoch at pair.com  Wed Nov 12 03:58:20 2003
From: dmurdoch at pair.com (dmurdoch@pair.com)
Date: Wed Nov 12 03:57:16 2003
Subject: [Rd] write.table quotes too much (PR#5042)
Message-ID: <20031112025820.75050F4DF@slim.kubism.ku.dk>

The code

> m <- matrix(1,2,2)
> write.table(m,'test.txt')

writes out a file that looks like this:

"X1" "X2"
"1" "1" "1"
"2" "1" "1"

According ?write.table, factors and character vectors should be quoted
by default, but this is quoting the numbers as well.  Also according
to the docs, the matrix m would be treated as data.frame(m), but if a
true data frame is passed in, the numbers don't get quoted.

The bug is due to the "else" near the beginning of write.table:

    if(!is.data.frame(x))
        x <- data.frame(x)
    else if(is.logical(quote) && quote)
        quote <- which(unlist(lapply(x, function(x)
                                    is.character(x) || is.factor(x))))

However, that looks intentional to me.  Is it really?

Duncan Murdoch


[Rd] write.table quotes too much (PR#5042)
dmurdoch@pair.com