[Rd] read.table() with quoted integers

Peter Meilstrup peter.meilstrup at gmail.com
Tue Oct 1 15:25:57 CEST 2013


On Tue, Oct 1, 2013 at 5:50 AM, Peter Meilstrup
<peter.meilstrup at gmail.com> wrote:
>
> On Mon, Sep 30, 2013 at 8:10 AM, Joris Meys <jorismeys at gmail.com> wrote:
>>
>> Regardless of whether "stored as character" is interpreted the R way or the
>> ASCII way, the point Joshua makes is rather valid. Mainly because
>> read.table has an argument quote with default value \"'. This means that at
>> least according to R, everything between either " or ' should be seen as of
>> type character and not integer.
>>
>> The only way these quotes can end up in a .csv file, is when in the
>> rendering program (often Excel), these integers are called "character"
>> inside the program as well. So they're not treated as integers by the
>> person that created the file, so R won't treat them
>> as integers either. Note that read.table does read the quoted integers as
>> characters, and only afterwards convert those.
>>
>> So yes, this is an issue with read.table.ffdf more than with R itself. And
>> the problem is indeed how integers are treated *the moment they are stored*.
>> This refering to the presence/absence of the quote character.
>
>
> This assumes too much about the program that creates the file.
>
> Quoted numeric values may be necessary in non-American locales which use the comma as decimal separator. (CSV files written in these locales often use something other than the comma for the field separator, but this is not required.)
>

Additionally, while CSV is a somewhat nebulous format, most attempts
at specifying it are clear that a quoted value, containing no special
characters, is to be treated _identically_ to the unquoted version.
The reason for the quote is to escape special characters which may be
present, not to impart type information. A CSV producing program may
simplify the logic of writing a file by always quoting, whether or not
the field would contain special characters when rendered.

http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm -- "When
importing CSV, do not reach down a layer and try to use the quotes to
impart type information to fields."

Peter



More information about the R-devel mailing list