From Kurt.Hornik at wu-wien.ac.at  Wed Nov 12 09:38:23 2003
From: Kurt.Hornik at wu-wien.ac.at (Kurt Hornik)
Date: Wed Nov 12 09:40:17 2003
Subject: [Rd] write.table quotes too much (PR#5042)
In-Reply-To: <20031112025820.75050F4DF@slim.kubism.ku.dk>
References: <20031112025820.75050F4DF@slim.kubism.ku.dk>
Message-ID: <16305.61823.637826.913353@mithrandir.hornik.net>

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


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