Skip to content

fread could set index as well #2633

@MichaelChirico

Description

@MichaelChirico

having a key argument for fread is quite nice, it helps cut down on code like:

DT = fread('path.csv')
setkey(DT, ID)

As well as being robust to changing the name of DT over time without having to track down every line where DT was used.

Since this wasn't any deep change to how fread works, but rather just entails running setkeyv just before returning ans, it would be easy to offer an index argument with similar goals.

DT = fread('path.csv', key = 'ID')
setindex(DT, ID2)
# could be streamlined as
DT = fread('path.csv', key = 'ID', index = 'ID2')

The only roadblock to implementing this right away is a small API issue -- should we allow multiple indices to be set, and if so what's the proper syntax? Most natural to me is: if index is given as atomic with length 1, strsplit it along , (as is done for key); with length >1, this is a single index (again, like key); and with index a list, *apply the logic from the first two cases to each element.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions