{
  "id": 7883,
  "title": "R FREAD for large files",
  "url": "/competitions/acquire-valued-shoppers-challenge/discussion/7883",
  "author_name": "",
  "post_date": "2014-04-26T14:44:30.910Z",
  "votes": 29,
  "comment_count": 10,
  "views": 25956,
  "content": "<p>Just discovered R package data.table for reading in large files. If read.csv is taking too long:</p>\n<p>install.packages(&quot;data.table&quot;)</p>\n<p>library(data.table)</p>\n<p>train &lt;- fread(&quot;train.csv&quot;)</p>\n<p>train&lt;-as.data.frame(train)</p>\n<p>Took about 5 minutes compared to 2 hours with read.csv.</p>",
  "messages": [
    {
      "id": "43081",
      "postDate": "04/26/2014 14:44:30",
      "content": "<p>Just discovered R package data.table for reading in large files. If read.csv is taking too long:</p>\n<p>install.packages(&quot;data.table&quot;)</p>\n<p>library(data.table)</p>\n<p>train &lt;- fread(&quot;train.csv&quot;)</p>\n<p>train&lt;-as.data.frame(train)</p>\n<p>Took about 5 minutes compared to 2 hours with read.csv.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "43096",
      "postDate": "04/26/2014 19:03:55",
      "content": "<p>fread is an amazing function-- it's actually quicker to fread() the raw .csv than to save() and load() the dataset!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "44462",
      "postDate": "05/13/2014 14:41:32",
      "content": "<p>wow great. thank you for your help !</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "44689",
      "postDate": "05/17/2014 02:08:51",
      "content": "<p>Use uncompressed RDS files after preparing data.table</p>\n<p>&gt; start.time &lt;- proc.time()<br>&gt; saveRDS(transactions, file=&quot;data/transactions_uncomp.Rds&quot;, compress=F)<br>&gt; end.time &lt;- proc.time()<br>&gt; cat(&quot;Elapsed; &quot;, end.time[3]-start.time[3], &quot;seconds.\\n&quot;)<br>Elapsed; 99.28 seconds.</p>\n\n<p>&gt; start.time &lt;- proc.time()<br>&gt; transactions &lt;- readRDS(file=&quot;data/transactions_uncomp.Rds&quot;)<br>&gt; end.time &lt;- proc.time()<br>&gt; cat(&quot;Elapsed; &quot;, end.time[3]-start.time[3], &quot;seconds.\\n&quot;)<br>Elapsed; 102.93 seconds.</p>\n\n<p>&gt; str(transactions)<br>Classes &#8216;data.table&#8217; and 'data.frame': 349655789 obs. of 11 variables:<br> $ id : Factor w/ 311541 levels &quot;100007447&quot;,&quot;100010021&quot;,..: 309397 309397 309397 309397 309397 309397 309397 309397 309397 309397 ...<br> $ chain : int 205 205 205 205 205 205 205 205 205 205 ...<br> $ dept : int 7 63 97 25 55 97 99 59 9 73 ...<br> $ category : int 707 6319 9753 2509 5555 9753 9909 5907 921 7344 ...<br> $ company : Factor w/ 32773 levels &quot;10000&quot;,&quot;1010000010&quot;,..: 22881 21689 3401 23605 21897 2430 10518 7758 184 15840 ...<br> $ brand : int 12564 17876 0 31373 32094 0 15343 2012 9209 20285 ...<br> $ date : Date, format: &quot;2012-03-02&quot; &quot;2012-03-02&quot; ...<br> $ productsize : num 12 64 1 16 16 1 16 16 4 8 ...<br> $ productmeasure : Factor w/ 12 levels &quot;&quot;,&quot;1&quot;,&quot;CT&quot;,&quot;FT&quot;,..: 8 8 3 8 8 3 8 8 8 3 ...<br> $ purchasequantity: int 1 1 1 1 2 1 1 1 2 1 ...<br> $ purchaseamount : num 7.59 1.59 5.99 1.99 10.38 ...<br> - attr(*, &quot;.internal.selfref&quot;)=&lt;externalptr&gt;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "49267",
      "postDate": "06/18/2014 03:26:22",
      "content": "<p>I agree this is an amazing function! I did have to add another argument to avoid getting nonsense in some fields with very large integer values.</p>\n\n<p>fread(&quot;transactions.csv&quot;,integer64=&quot;character&quot;)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "49976",
      "postDate": "07/02/2014 21:12:23",
      "content": "<p>Just require(bit64) and then you'll see the bit64::integer64 type properly displayed.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "57285",
      "postDate": "11/04/2014 09:48:13",
      "content": "<p>Hi I am learning data analysis on this project, I know the competition is over but learning for knowledge. For fread how can I see 64 bit integers as it is displaying some junk data?</p>\n<p>how do i get bit64?</p>\n<p>can someone help in it?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "57286",
      "postDate": "11/04/2014 10:34:14",
      "content": "<p>print(DT) &nbsp;# displays &quot;junk&quot; for integer64 column</p>\n<p>install.packages(&quot;bit64&quot;)</p>\n<p>require(bit64)</p>\n<p>print(DT) &nbsp; # now displays integer64 nicely</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "57288",
      "postDate": "11/04/2014 11:09:47",
      "content": "<p>Wow Thanks a lot that works...:)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "71210",
      "postDate": "04/10/2015 14:18:52",
      "content": "<p>Hi All,</p>\n<p>i am using Windows 7 OS in my 64 bit machine and installed R 3.0.2 version. i am using 8 GB RAM. I have installed data.table package 1.9.4 version. i am using fread() to read a 3 GB file which has 476147 rows and 556 columns.<br>&nbsp;<br>when i read using fread() it makes R session aborted and gives R fatal error. when i am using read.csv() it reads it successfully but it take around 20 mins.&nbsp;<br>&nbsp;<br>Any body knows why fread() is not working in this case?</p>\n<p>- Solomon</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "71396",
      "postDate": "04/13/2015 17:54:37",
      "content": "<p>Please install v1.9.5 from GitHub and try again. &nbsp;Currently there's a good chance it is fixed already. If it still crashes then rerun with verbose=TRUE and include the output in a new issue on GitHub. If the trace output is not enough and we need the file to reproduce, we'll let you know. Or include the file, or subset of, up front can help.</p>\n<p>- Matt</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 43096,
      "author_name": "zachmayer",
      "author_url": "",
      "post_date": "04/26/2014 19:03:55",
      "content": "<p>fread is an amazing function-- it's actually quicker to fread() the raw .csv than to save() and load() the dataset!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 44462,
      "author_name": "taekkyunshin",
      "author_url": "",
      "post_date": "05/13/2014 14:41:32",
      "content": "<p>wow great. thank you for your help !</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 44689,
      "author_name": "databystander",
      "author_url": "",
      "post_date": "05/17/2014 02:08:51",
      "content": "<p>Use uncompressed RDS files after preparing data.table</p>\n<p>&gt; start.time &lt;- proc.time()<br>&gt; saveRDS(transactions, file=&quot;data/transactions_uncomp.Rds&quot;, compress=F)<br>&gt; end.time &lt;- proc.time()<br>&gt; cat(&quot;Elapsed; &quot;, end.time[3]-start.time[3], &quot;seconds.\\n&quot;)<br>Elapsed; 99.28 seconds.</p>\n\n<p>&gt; start.time &lt;- proc.time()<br>&gt; transactions &lt;- readRDS(file=&quot;data/transactions_uncomp.Rds&quot;)<br>&gt; end.time &lt;- proc.time()<br>&gt; cat(&quot;Elapsed; &quot;, end.time[3]-start.time[3], &quot;seconds.\\n&quot;)<br>Elapsed; 102.93 seconds.</p>\n\n<p>&gt; str(transactions)<br>Classes &#8216;data.table&#8217; and 'data.frame': 349655789 obs. of 11 variables:<br> $ id : Factor w/ 311541 levels &quot;100007447&quot;,&quot;100010021&quot;,..: 309397 309397 309397 309397 309397 309397 309397 309397 309397 309397 ...<br> $ chain : int 205 205 205 205 205 205 205 205 205 205 ...<br> $ dept : int 7 63 97 25 55 97 99 59 9 73 ...<br> $ category : int 707 6319 9753 2509 5555 9753 9909 5907 921 7344 ...<br> $ company : Factor w/ 32773 levels &quot;10000&quot;,&quot;1010000010&quot;,..: 22881 21689 3401 23605 21897 2430 10518 7758 184 15840 ...<br> $ brand : int 12564 17876 0 31373 32094 0 15343 2012 9209 20285 ...<br> $ date : Date, format: &quot;2012-03-02&quot; &quot;2012-03-02&quot; ...<br> $ productsize : num 12 64 1 16 16 1 16 16 4 8 ...<br> $ productmeasure : Factor w/ 12 levels &quot;&quot;,&quot;1&quot;,&quot;CT&quot;,&quot;FT&quot;,..: 8 8 3 8 8 3 8 8 8 3 ...<br> $ purchasequantity: int 1 1 1 1 2 1 1 1 2 1 ...<br> $ purchaseamount : num 7.59 1.59 5.99 1.99 10.38 ...<br> - attr(*, &quot;.internal.selfref&quot;)=&lt;externalptr&gt;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 49267,
      "author_name": "swhardy",
      "author_url": "",
      "post_date": "06/18/2014 03:26:22",
      "content": "<p>I agree this is an amazing function! I did have to add another argument to avoid getting nonsense in some fields with very large integer values.</p>\n\n<p>fread(&quot;transactions.csv&quot;,integer64=&quot;character&quot;)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 49976,
      "author_name": "mattdowle",
      "author_url": "",
      "post_date": "07/02/2014 21:12:23",
      "content": "<p>Just require(bit64) and then you'll see the bit64::integer64 type properly displayed.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 57285,
      "author_name": "shainanhemrajani",
      "author_url": "",
      "post_date": "11/04/2014 09:48:13",
      "content": "<p>Hi I am learning data analysis on this project, I know the competition is over but learning for knowledge. For fread how can I see 64 bit integers as it is displaying some junk data?</p>\n<p>how do i get bit64?</p>\n<p>can someone help in it?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 57286,
      "author_name": "mattdowle",
      "author_url": "",
      "post_date": "11/04/2014 10:34:14",
      "content": "<p>print(DT) &nbsp;# displays &quot;junk&quot; for integer64 column</p>\n<p>install.packages(&quot;bit64&quot;)</p>\n<p>require(bit64)</p>\n<p>print(DT) &nbsp; # now displays integer64 nicely</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 57288,
      "author_name": "shainanhemrajani",
      "author_url": "",
      "post_date": "11/04/2014 11:09:47",
      "content": "<p>Wow Thanks a lot that works...:)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 71210,
      "author_name": "solomonpushparaj",
      "author_url": "",
      "post_date": "04/10/2015 14:18:52",
      "content": "<p>Hi All,</p>\n<p>i am using Windows 7 OS in my 64 bit machine and installed R 3.0.2 version. i am using 8 GB RAM. I have installed data.table package 1.9.4 version. i am using fread() to read a 3 GB file which has 476147 rows and 556 columns.<br>&nbsp;<br>when i read using fread() it makes R session aborted and gives R fatal error. when i am using read.csv() it reads it successfully but it take around 20 mins.&nbsp;<br>&nbsp;<br>Any body knows why fread() is not working in this case?</p>\n<p>- Solomon</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 71396,
      "author_name": "mattdowle",
      "author_url": "",
      "post_date": "04/13/2015 17:54:37",
      "content": "<p>Please install v1.9.5 from GitHub and try again. &nbsp;Currently there's a good chance it is fixed already. If it still crashes then rerun with verbose=TRUE and include the output in a new issue on GitHub. If the trace output is not enough and we need the file to reproduce, we'll let you know. Or include the file, or subset of, up front can help.</p>\n<p>- Matt</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "43081": "",
    "43096": "",
    "44462": "",
    "44689": "",
    "49267": "",
    "49976": "",
    "57285": "",
    "57286": "",
    "57288": "",
    "71210": "",
    "71396": ""
  },
  "source": "meta"
}