Skip to content

fread may fail to parse valid file when dec=',' #2750

@st-pasha

Description

@st-pasha
> fread('a,b,c,d\n1e1,1e2,1e3,"4,0001"\n1,2,3,4\n', dec=',')
       a     b     c      d
   <num> <num> <num>  <num>
1:    10   100  1000 4.0001
Warning message:
In fread("a,b,c,d\n1e1,1e2,1e3,\"4,0001\"\n1,2,3,4\n", dec = ",") :
  Discarded single-line footer: <<1,2,3,4>>

This happens because float parser greedily consumes 1,2 as a single token, whereas without quotes it must be parsed as 2 separate fields.

In addition, the "Details" section in documentation has the following information (which is long since being outdated):

‘fread’ uses C function ‘strtod’ to read numeric data; e.g.,
‘1.23’ or ‘1,23’. ‘strtod’ retrieves the decimal separator (‘.’ or
‘,’ usually) from the locale of the R session rather than as an
argument passed to the ‘strtod’ function. So for
‘fread(...,dec=",")’ to work, ‘fread’ changes this (and only this)
R session's locale temporarily to a locale which provides the
desired decimal separator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions