Skip to content

Inconsistent behaviour with read_csv and skip > #rows  #119

@coolbutuseless

Description

@coolbutuseless
  1. When col_types is specified and skip is equal to or greater than the number of actual rows, read_csv() returns a data.frame with 1 row.
  2. When col_types is not specified and skip is equal to or greater than the number of actual rows, read_csv() throws an error.

I think Case1 is wrong to return a row of results when there aren't any, and should probably return a zero-row data.frame.

EDIT: Case 2 is handled OK i.e. If column types aren't specified, and there are no rows from which to infer type, you can't really return anything sensible.

I found this inconsistency when doing chunked reads from a large CSV file, and a zero-row data.frame was going to be an indicator that I'd run out of data.

> read_csv("1,2\n3,4", col_names=c('a', 'b'), col_types='ii')
Source: local data frame [2 x 2]

  a b
1 1 2
2 3 4
> 
> read_csv("1,2\n3,4", col_names=c('a', 'b'), col_types='ii', skip=2)
Source: local data frame [1 x 2]

   a  b
1 NA NA
> 
> read_csv("1,2\n3,4", col_names=c('a', 'b'), skip=2)
Error: You have 2 column names, but 0 columns

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions