[R] Using read.table to read file created with read.table and qmethod = "escape"
David Winsemius
dwinsemius at comcast.net
Thu Apr 8 17:01:44 CEST 2010
On Apr 8, 2010, at 10:01 AM, Hadley Wickham wrote:
>>> Can write.table and read.table really be so asymmetric?
>>
>> write() is a wrapper for cat() and read() is a wrapper for scan()
>> so the
>> question should really be can cat() and scan() be so asymmetric.
>> Looking at
>> their help pages, I would say that at least some degree of
>> asymmetry is
>> plausible. Perhaps using save() with load() , or dput() with
>> dget(), which
>> are pairings that promise to have symmetry?
>
> Why should I have to care about the internal implementation details?
> This is one of the things that really frustrates me (and other new
> users of R) - read.table/write.table and read.csv/write.csv are named
> symmetrically, but do not work symmetrically.
I hope you won't take it amiss if I think it's great that you (in
particular) get frustrated. You have already turned frustrations in
other areas into productivity tools. I do have one further observation
on this one that extends my earlier suggestion regarding the fact that
this semi-strange behavior was a factor-type related issue of
asymmetry rather than a character-type one:
> df <- data.frame(a = "a\"b", v = 4, z = "this is: A, B, C",
stringsAsFactors=FALSE)
> write.csv(df, "test.csv", row.names = FALSE)
> df2<- read.csv("test.csv", header=TRUE, stringsAsFactors=FALSE)
> df2
a v z
1 a"b 4 this is: A, B, C
> df2$a
[1] "a\"b"
Might I inquire if anyone know why displaying the dataframe version of
the "a" element is different on the console from the vector version? I
think it related to this behavior:
> df2[[1]]
[1] "a\"b"
> df2[1]
a
1 a"b
>
> Hadley
>
>
> --
> Assistant Professor / Dobelman Family Junior Chair
> Department of Statistics / Rice University
> http://had.co.nz/
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list