jpalmucci@machineinsight.com
2004-Aug-14 06:27 UTC
[Rd] write.table doesn't quote column names properly (PR#7171)
Full_Name: Jeff Palmucci Version: trunk OS: Windows Submission from: (NULL) (207.180.176.235) write.table doesn't quote the column names using qmethod. Here is the diff of the fix with revision 30658 svn diff write.table.R Index: write.table.R ==================================================================--- write.table.R (revision 30658) +++ write.table.R (working copy) @@ -76,21 +76,23 @@ stop(paste("argument", sQuote("file"), "must be a character string or connection")) + + qstring <- # quoted embedded quote string + switch(qmethod, + "escape" = '\\\\"', + "double" = '""') + if(!is.null(col.names)) { if(append) warning("appending column names to file") if(!is.null(quote)) - col.names <- paste("\"", col.names, "\"", sep = "") + col.names <- paste("\"", gsub('"', qstring, col.names), "\"", sep = "") writeLines(paste(col.names, collapse = sep), file, sep = eol) } if (NROW(x) == 0) return(invisible(x)) - - qstring <- # quoted embedded quote string - switch(qmethod, - "escape" = '\\\\"', - "double" = '""') + for(i in quote) x[, i] <- paste('"', gsub('"', qstring, as.character(x[, i])), '"', sep = "")