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

ripley at stats.ox.ac.uk ripley at stats.ox.ac.uk
Wed Jul 5 14:22:12 CEST 2006


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 at 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 at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

-- 
Brian D. Ripley,                  ripley at 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



More information about the R-devel mailing list