[Rd] write.table quotes too much (PR#5042)

dmurdoch at pair.com dmurdoch at pair.com
Wed Nov 12 03:58:20 MET 2003

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:

        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

More information about the R-devel mailing list