Skip to content

fread doesn't trim whitespace at the beginning of fields #1000

Description

@gkalnytskyi

fread from data.table 1.9.4 doesn't remove whitespace at the beginning of the fields.

Here is the example of the file content:

id, time, obsType, comment
90, 2014-01-03 03:43:31.0138, "l2", "69D88XZ M7ADF H1RSV4"
91, 2014-01-05 13:51:54.2273, "m3", "NULL"

Let's say, it is read by standard read.csv function

data1 <- read.csv("./file.dat", header=TRUE, colClasses=c("integer", "POSIXct", "factor", "character"))

Then names of the columns will be displayed correctly:

names(data1)
[1] "id"      "time"    "obsType" "comment"

But when exactly the same data is read by fread it doesn't remove beginning spaces from the heading and data:

data2 <- fread(input="./sample_data.csv",header=TRUE, colClasses=c("integer", "POSIXct", "factor", "character"))
names(data2)
[1] "id"       " time"    " obsType" " comment"

data[1,2]
"2014-01-03 03:43:31 EET"
unlist(data2[1,2,with=FALSE])
                       time 
" 2014-01-05 13:51:54.2273" 

Activity

  1. added this to the v1.9.6 milestone on Sep 8, 2015
  2. arunsrinivasan commented on Sep 16, 2015

    @arunsrinivasan
    Member

    Fixed in devel. Please upgrade and test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions