Re: [Rd] write.table does not quote col.names properly (PR#9044)

From: <ripley_at_stats.ox.ac.uk>
Date: Wed 05 Jul 2006 - 12:22:12 GMT


As this is documented to quote nothing if quote=FALSE, the patch is incorrect. We need to handle quoting of colunm names separately.

Fixed for 2.3.1 patched.

On Thu, 29 Jun 2006, mwtoews@sfu.ca wrote:

> Full_Name: Michael Toews
> Version: 2.3.1
> OS: Mac OS 10.4.6 and WinXP/SP2
> Submission from: (NULL) (24.80.163.133)
>
>
> This bug also affects related functions (write.csv, etc.), and can be
> demonstrated using either a matrix or data frame:
>
> m <- matrix(1:9,nrow=3,
> dimnames=list(c("A","B","C"),
> c("I","II","III")))
>
> write.table(m)
> write.table(m,col.names=FALSE)
> write.table(m,row.names=FALSE)
>
> Note that the last 'write.table' call has unquoted column headers. A suggested
> fix for this problem is:
>
> Index: write.table.R
> ===================================================================
> --- write.table.R (revision 38447)
> +++ write.table.R (working copy)
> @@ -86,9 +86,8 @@
> if(!is.null(col.names)) {
> if(append)
> warning("appending column names to file")
> - if(length(quote))
> - col.names <- paste("\"", gsub('"', qstring, col.names),
> - "\"", sep = "")
> + col.names <- paste("\"", gsub('"', qstring, col.names),
> + "\"", sep = "")
> writeLines(paste(col.names, collapse = sep), file, sep = eol)
> }
>
>
> However, it is unknown why the "if(length(quote))" is used in the original code
> (please check before a commit). The length of quote will be 0 here, since the
> matrix has all numbers.
> This bug does not occur with a data frame with mixed number and factor/character
> columns.
> +mt
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed Jul 05 22:29:50 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 05 Jul 2006 - 14:27:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.