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 could set index as well #2633

Closed
MichaelChirico opened this issue Feb 19, 2018 · 2 comments
Closed

fread could set index as well #2633

MichaelChirico opened this issue Feb 19, 2018 · 2 comments
Labels
Milestone

Comments

@MichaelChirico
Copy link
Member

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.

@jangorecki
Copy link
Member

There is no point to add feature for making single index only. It would require to take a list of character vectors as input and just loop setindexv over it.

@jangorecki
Copy link
Member

lets implement this after #2695

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

No branches or pull requests

3 participants