[Rd] Suggestion: quote POSIXlt and POSIXct in write.table()

From: Noah Lorang <lorang_at_gmail.com>
Date: Tue, 22 Mar 2011 15:45:12 -0400


Currently, if you call write.table() on a data.frame that includes a POSIXlt or POSIXct variable, with the default options (space delimited), you won't then be able to read that file back in using read.table because the POSIXlt and POSIXct won't get quoted, and they contain a space in them when written to the file.

For an example, see:
https://gist.github.com/881799

A one line change to write.table() to quote POSIXlt and POSIXct by default can fix this:

      if (qset) 
            quote <- if (length(x)) 
                which(unlist(lapply(x, function(x) is.character(x) || 
-                  is.factor(x))))
+                  is.factor(x) || is(x, "POSIXlt") || is(x, "POSIXct"))))
            else numeric(0L)

I get all the theoretical reasons for why this shouldn't be a big deal (I could use read.csv and write.csv instead of read.table and write.table, or convert to character before writing if I was set on using write.table), but this is the sort of thing that just confuses people with limited upside. I can't think of a way in which this change would break anyone's legacy code.

Best,
Noah

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 22 Mar 2011 - 19:53:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Mar 2011 - 20:00:35 GMT.

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

list of date sections of archive