Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fread() warning message: Read less rows than were allocated #1239

Closed
hshipper opened this issue Jul 22, 2015 · 2 comments
Closed

fread() warning message: Read less rows than were allocated #1239

hshipper opened this issue Jul 22, 2015 · 2 comments
Assignees
Milestone

Comments

@hshipper
Copy link

The data used that produced the following bug can be found here: https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2. I've tried creating smaller subsets of this data, but my attempts result in different errors that stem from issues within my methods of creating the data, not the data.table package (as best I can tell).

I switched to the development version 1.9.5 because I was having trouble using fread from 1.9.4 for a data set that contained embedded quotes in one of the columns. The development version produced the proper data.table, but did provide me with the following warning message:

Warning message:
In fread("~/Data/repdata-data-StormData.csv", header = TRUE) :
  Read less rows (902297) than were allocated (967216). Run again with verbose=TRUE and please report.

Here is the code and output with verbose = TRUE:

Input contains no \n. Taking this to be a filename to open
File opened, filesize is 0.523066 GB.
Memory mapping ... ok
Detected eol as \r\n (CRLF) in that order, the Windows standard.
Positioned on line 1 after skip or autostart
This line is the autostart and not blank so searching up for the last non-blank ... line 1
Detecting sep ... ','
Detected 37 columns. Longest stretch was from line 1 to line 30
Starting data input on line 1 (either column names or first row of data). First 10 characters: "STATE__",
'header' changed by user from 'auto' to TRUE
Count of eol: 1307675 (including 1 at the end)
Count of sep: 34819802
nrow = MIN( nsep [34819802] / ncol [37] -1, neol [1307675] - nblank [1] ) = 967216
Type codes (   first 5 rows): 3444344430000303003343333430000333303
Type codes (+ middle 5 rows): 3444344434444303443343333434440333343
Type codes (+   last 5 rows): 3444344434444303443343333434444333343
Type codes: 3444344434444303443343333434444333343 (after applying colClasses and integer64)
Type codes: 3444344434444303443343333434444333343 (after applying drop or select (if supplied)
Allocating 37 column slots (37 - 0 dropped)
Read 902297 rows and 37 (of 37) columns from 0.523 GB file in 00:00:08
   0.050s (  1%) Memory map (rerun may be quicker)
   0.000s (  0%) sep and header detection
   1.210s ( 16%) Count rows (wc -l)
   0.000s (  0%) Column type detection (first, middle and last 5 rows)
   0.910s ( 12%) Allocation of 902297x37 result (xMB) in RAM
   5.430s ( 71%) Reading data
   0.000s (  0%) Allocation for type bumps (if any), including gc time if triggered
   0.000s (  0%) Coercing data already read in type bumps (if any)
   0.050s (  1%) Changing na.strings to NA
   7.650s        Total
        STATE__           BGN_DATE    BGN_TIME TIME_ZONE COUNTY   COUNTYNAME STATE     EVTYPE BGN_RANGE BGN_AZI
     1:       1  4/18/1950 0:00:00        0130       CST     97       MOBILE    AL    TORNADO         0        
     2:       1  4/18/1950 0:00:00        0145       CST      3      BALDWIN    AL    TORNADO         0        
     3:       1  2/20/1951 0:00:00        1600       CST     57      FAYETTE    AL    TORNADO         0        
     4:       1   6/8/1951 0:00:00        0900       CST     89      MADISON    AL    TORNADO         0        
     5:       1 11/15/1951 0:00:00        1500       CST     43      CULLMAN    AL    TORNADO         0        
    ---                                                                                                        
902293:      56 11/30/2011 0:00:00 10:30:00 PM       MST      7 WYZ007 - 017    WY  HIGH WIND         0        
902294:      30 11/10/2011 0:00:00 02:48:00 PM       MST      9 MTZ009 - 010    MT  HIGH WIND         0        
902295:       2  11/8/2011 0:00:00 02:58:00 PM       AKS    213       AKZ213    AK  HIGH WIND         0        
902296:       2  11/9/2011 0:00:00 10:21:00 AM       AKS    202       AKZ202    AK   BLIZZARD         0        
902297:       1 11/28/2011 0:00:00 08:00:00 PM       CST      6       ALZ006    AL HEAVY SNOW         0        
        BGN_LOCATI           END_DATE    END_TIME COUNTY_END COUNTYENDN END_RANGE END_AZI END_LOCATI LENGTH
     1:                                                    0         NA         0                      14.0
     2:                                                    0         NA         0                       2.0
     3:                                                    0         NA         0                       0.1
     4:                                                    0         NA         0                       0.0
     5:                                                    0         NA         0                       0.0
    ---                                                                                                    
902293:            11/30/2011 0:00:00 10:30:00 PM          0         NA         0                       0.0
902294:            11/10/2011 0:00:00 02:48:00 PM          0         NA         0                       0.0
902295:             11/9/2011 0:00:00 01:15:00 PM          0         NA         0                       0.0
902296:             11/9/2011 0:00:00 05:00:00 PM          0         NA         0                       0.0
902297:            11/29/2011 0:00:00 04:00:00 AM          0         NA         0                       0.0
        WIDTH F MAG FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP WFO                STATEOFFIC
     1:   100 3   0          0       15    25.0          K       0                                         
     2:   150 2   0          0        0     2.5          K       0                                         
     3:   123 2   0          0        2    25.0          K       0                                         
     4:   100 2   0          0        2     2.5          K       0                                         
     5:   150 2   0          0        2     2.5          K       0                                         
    ---                                                                                                    
902293:     0    66          0        0     0.0          K       0          K RIW WYOMING, Central and West
902294:     0    52          0        0     0.0          K       0          K TFX          MONTANA, Central
902295:     0    81          0        0     0.0          K       0          K AFG          ALASKA, Northern
902296:     0     0          0        0     0.0          K       0          K AFG          ALASKA, Northern
902297:     0     0          0        0     0.0          K       0          K HUN            ALABAMA, North
                                                                               ZONENAMES LATITUDE LONGITUDE
     1:                                                                                      3040      8812
     2:                                                                                      3042      8755
     3:                                                                                      3340      8742
     4:                                                                                      3458      8626
     5:                                                                                      3412      8642
    ---                                                                                                    
902293: OWL CREEK & BRIDGER MOUNTAINS - OWL CREEK & BRIDGER MOUNTAINS - WIND RIVER BASIN        0         0
902294:        NORTH ROCKY MOUNTAIN FRONT - NORTH ROCKY MOUNTAIN FRONT - EASTERN GLACIER        0         0
902295:                    ST LAWRENCE IS. BERING STRAIT - ST LAWRENCE IS. BERING STRAIT        0         0
902296:                                    NORTHERN ARCTIC COAST - NORTHERN ARCTIC COAST        0         0
902297:                                                                MADISON - MADISON        0         0
        LATITUDE_E LONGITUDE_
     1:       3051       8806
     2:          0          0
     3:          0          0
     4:          0          0
     5:          0          0
    ---                      
902293:          0          0
902294:          0          0
902295:          0          0
902296:          0          0
902297:          0          0
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        REMARKS
     1:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
     2:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
     3:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
     4:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
     5:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
    ---                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
902293:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           EPISODE NARRATIVE: A strong cold front moved south through north central Wyoming bringing high wind to the Meeteetse area and along the south slopes of the western Owl Creek Range. Wind gusts to 76 mph were recorded at Madden Reservoir.EVENT NARRATIVE: 
902294:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      EPISODE NARRATIVE: A strong westerly flow aloft produced gusty winds at the surface along the Rocky Mountain front and over the plains of Central Montana. Wind gusts in excess of 60 mph were reported.EVENT NARRATIVE: A wind gust to 60 mph was reported at East Glacier Park 1ENE (the Two Medicine DOT site).
902295: EPISODE NARRATIVE: A 960 mb low over the southern Aleutians at 0300AKST on the 8th intensified to 945 mb near the Gulf of Anadyr by 2100AKST on the 8th. The low crossed the Chukotsk Peninsula as a 956 mb low at 0900AKST on the 9th, and moved into the southern Chukchi Sea as a 958 mb low by 2100AKST on the 9th. The low then tracked to the northwest and weakened to 975 mb about 150 miles north of Wrangel Island by 1500AKST on the 10th. The storm was one of the strongest storms to impact the west coast of Alaska since November 1974. \n\nZone 201: Blizzard conditions were observed at Wainwright from approximately 1153AKST through 1611AKST on the 9th. The visibility was frequently reduced to one quarter mile in snow and blowing snow. There was a peak wind gust to 43kt (50 mph) at the Wainwright ASOS. During this event, there was also a peak wind gust to \n68 kt (78 mph) at the Cape Lisburne AWOS. \n\nZone 202: Blizzard conditions were observed at Barrow from approximately 1021AKST through 1700AKST on the 9th. The visibility was frequently reduced to one quarter mile or less in blowing snow. There was a peak wind gust to 46 kt (53 mph) at the Barrow ASOS. \n\nZone 207: Blizzard conditions were observed at Kivalina from approximately 0400AKST through 1230AKST on the 9th. The visibility was frequently reduced to one quarter of a mile in snow and blowing snow. There was a peak wind gust to 61 kt (70 mph) at the Kivalina ASOS.  The doors to the village transportation shed were blown out to sea.  Many homes lost portions of their tin roofing, and satellite dishes were ripped off of roofs. One home had its door blown off.  At Point Hope, severe blizzard conditions were observed. There was a peak wind gust of 68 kt (78 mph) at the Point Hope AWOS before power was lost to the AWOS. It was estimated that the wind gusted as high as 85 mph in the village during the height of the storm during the morning and early afternoon hours on the 9th. Five power poles were knocked down in the storm EVENT NARRATIVE: 
902296: EPISODE NARRATIVE: A 960 mb low over the southern Aleutians at 0300AKST on the 8th intensified to 945 mb near the Gulf of Anadyr by 2100AKST on the 8th. The low crossed the Chukotsk Peninsula as a 956 mb low at 0900AKST on the 9th, and moved into the southern Chukchi Sea as a 958 mb low by 2100AKST on the 9th. The low then tracked to the northwest and weakened to 975 mb about 150 miles north of Wrangel Island by 1500AKST on the 10th. The storm was one of the strongest storms to impact the west coast of Alaska since November 1974. \n\nZone 201: Blizzard conditions were observed at Wainwright from approximately 1153AKST through 1611AKST on the 9th. The visibility was frequently reduced to one quarter mile in snow and blowing snow. There was a peak wind gust to 43kt (50 mph) at the Wainwright ASOS. During this event, there was also a peak wind gust to \n68 kt (78 mph) at the Cape Lisburne AWOS. \n\nZone 202: Blizzard conditions were observed at Barrow from approximately 1021AKST through 1700AKST on the 9th. The visibility was frequently reduced to one quarter mile or less in blowing snow. There was a peak wind gust to 46 kt (53 mph) at the Barrow ASOS. \n\nZone 207: Blizzard conditions were observed at Kivalina from approximately 0400AKST through 1230AKST on the 9th. The visibility was frequently reduced to one quarter of a mile in snow and blowing snow. There was a peak wind gust to 61 kt (70 mph) at the Kivalina ASOS.  The doors to the village transportation shed were blown out to sea.  Many homes lost portions of their tin roofing, and satellite dishes were ripped off of roofs. One home had its door blown off.  At Point Hope, severe blizzard conditions were observed. There was a peak wind gust of 68 kt (78 mph) at the Point Hope AWOS before power was lost to the AWOS. It was estimated that the wind gusted as high as 85 mph in the village during the height of the storm during the morning and early afternoon hours on the 9th. Five power poles were knocked down in the storm EVENT NARRATIVE: 
902297:                           EPISODE NARRATIVE: An intense upper level low developed on the 28th at the base of a highly amplified upper trough across the Great Lakes and Mississippi Valley.  The upper low closed off over the mid South and tracked northeast across the Tennessee Valley during the morning of the 29th.   A warm conveyor belt of heavy rainfall developed in advance of the low which dumped from around 2 to over 5 inches of rain across the eastern two thirds of north Alabama and middle Tennessee.  The highest rain amounts were recorded in Jackson and DeKalb Counties with 3 to 5 inches.  The rain fell over 24 to 36 hour period, with rainfall remaining light to moderate during most its duration.  The rainfall resulted in minor river flooding along the Little River, Big Wills Creek and Paint Rock.   A landslide occurred on Highway 35 just north of Section in Jackson County.  A driver was trapped in his vehicle, but was rescued unharmed.  Trees, boulders and debris blocked 100 to 250 yards of Highway 35.\n\nThe rain mixed with and changed to snow across north Alabama during the afternoon and  evening hours of the 28th, and lasted into the 29th.  The heaviest bursts of snow occurred in northwest Alabama during the afternoon and evening hours, and in north central and northeast Alabama during the overnight and morning hours.  Since ground temperatures were in the 50s, and air temperatures in valley areas only dropped into the mid 30s, most of the snowfall melted on impact with mostly trace amounts reported in valley locations.  However, above 1500 foot elevation, snow accumulations of 1 to 2 inches were reported.  The heaviest amount was 2.3 inches on Monte Sano Mountain, about 5 miles northeast of Huntsville.EVENT NARRATIVE: Snowfall accumulations of up to 2.3 inches were reported on the higher elevations of eastern Madison County.  A snow accumulation of 1.5 inches was reported 2.7 miles south of Gurley, while 2.3 inches was reported 3 miles east of Huntsville atop Monte Sano Mountain.
        REFNUM
     1:      1
     2:      2
     3:      3
     4:      4
     5:      5
    ---       
902293: 902293
902294: 902294
902295: 902295
902296: 902296
902297: 902297
Warning message:
In fread("~/Data/repdata-data-StormData.csv", header = TRUE, verbose = TRUE) :
  Read less rows (902297) than were allocated (967216). Run again with verbose=TRUE and please report.
@arunsrinivasan
Copy link
Member

The file is read completely and correctly. The issue is that fread() is bad at counting the number of rows in specific cases (which your case falls under).

Here's an example:

require(data.table)
text="a,b\nqq,rr\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n\"bla,\n,\n,\nbla\",bla\n"
fread(text, verbose=TRUE)
Input contains a \n (or is ""). Taking this to be text input (not a filename)
Detected eol as \n only (no \r afterwards), the UNIX and Mac standard.
Positioned on line 1 after skip or autostart
This line is the autostart and not blank so searching up for the last non-blank ... line 1
Detecting sep ... ','
Detected 2 columns. Longest stretch was from line 1 to line 27
Starting data input on line 1 (either column names or first row of data). First 10 characters: a,b
All the fields on line 1 are character fields. Treating as the column names.
Count of eol: 102 (including 1 at the end)
Count of sep: 101
nrow = MIN( nsep [101] / ncol [2] -1, neol [102] - nblank [1] ) = 101 # <~~~~~~
Type codes (   first 5 rows): 44
Type codes (+ middle 5 rows): 44
Type codes (+   last 5 rows): 44
Type codes: 44 (after applying colClasses and integer64)
Type codes: 44 (after applying drop or select (if supplied)
Allocating 2 column slots (2 - 0 dropped)
Read slightly fewer rows (26) than were allocated (101). # <~~~~~~~
   0.000s (  6%) Memory map (rerun may be quicker)
   0.000s ( 23%) sep and header detection
   0.000s ( 10%) Count rows (wc -l)
   0.000s ( 53%) Column type detection (first, middle and last 5 rows)
   0.000s (  3%) Allocation of 26x2 result (xMB) in RAM
   0.000s (  1%) Reading data
   0.000s (  0%) Allocation for type bumps (if any), including gc time if triggered
   0.000s (  0%) Coercing data already read in type bumps (if any)
   0.000s (  4%) Changing na.strings to NA
   0.000s        Total
                  a   b
 1:              qq  rr
 2: bla,\n,\n,\nbla bla
 3: bla,\n,\n,\nbla bla
 4: bla,\n,\n,\nbla bla
 5: bla,\n,\n,\nbla bla
 6: bla,\n,\n,\nbla bla
 7: bla,\n,\n,\nbla bla
 8: bla,\n,\n,\nbla bla
 9: bla,\n,\n,\nbla bla
10: bla,\n,\n,\nbla bla
11: bla,\n,\n,\nbla bla
12: bla,\n,\n,\nbla bla
13: bla,\n,\n,\nbla bla
14: bla,\n,\n,\nbla bla
15: bla,\n,\n,\nbla bla
16: bla,\n,\n,\nbla bla
17: bla,\n,\n,\nbla bla
18: bla,\n,\n,\nbla bla
19: bla,\n,\n,\nbla bla
20: bla,\n,\n,\nbla bla
21: bla,\n,\n,\nbla bla
22: bla,\n,\n,\nbla bla
23: bla,\n,\n,\nbla bla
24: bla,\n,\n,\nbla bla
25: bla,\n,\n,\nbla bla
26: bla,\n,\n,\nbla bla
                  a   b

Note the lines highlighted with arrow where the number of lines are computed incorrectly.

@arunsrinivasan
Copy link
Member

Closing as duplicate of #1116.

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

No branches or pull requests

2 participants