Noah Lorang
2011-Mar-22 19:45 UTC
[Rd] Suggestion: quote POSIXlt and POSIXct in write.table()
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]]