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

Kurt Hornik Kurt.Hornik at wu-wien.ac.at
Wed Nov 12 09:38:23 MET 2003


>>>>> dmurdoch  writes:

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

Yes, but maybe not quite right :-)

I think we could change this to remove the 'else', but pls check the
consequences.

-k



More information about the R-devel mailing list