Skip to content

when 'select' argument is provided, columns should be returned in the order provided to that argument  #1445

Description

@arunsrinivasan
require(data.table) # devel
fread("a,c,b\n1,2,3", select=c("b", "c"))
#    c b
#1: 2 3

I'd have expected the columns to be in the order provided to select. Just ran across this bug today.

Activity

  1. added this to the v1.9.8 milestone on Nov 26, 2015
  2. MichaelChirico commented on Dec 1, 2015

    @MichaelChirico
    Member

    Any reason to care about the column order? I've noticed this but never particularly minded. Usually the order I specify them in is meaningless.

  3. arunsrinivasan commented on Dec 1, 2015

    @arunsrinivasan
    MemberAuthor

    @MichaelChirico perhaps because the reason I ran into this issue is due to recently implemented col.names argument. You can't use col.names argument together with select if you can't be sure of the order of columns in the result.

    fread(my_file, select=c("b", "c"), col.names = c("B", "C"))

    names the columns wrongly in this case.. and so one has to do:

    cols = c("b", "c")
    dt = fread(my_file, select=cols)
    setcolorder(dt, cols)
    setnames(dt, cols, c("B", "C"))
  4. MichaelChirico commented on Dec 1, 2015

    @MichaelChirico
    Member

    @arunsrinivasan duly noted, I had missed the col.names update. Very useful.

  5. mattdowle commented on Jan 8, 2016

    @mattdowle
    Member

    Agreed. And fread should error if the column requested isn't present.

    > fread("a,c,b\n1,2,3", select=c("b", "foo"))
       b
    1: 3 
    # To add:  Error: column name "foo" passed to 'select=' not found in data
  6. added a commit that references this issue on Jan 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions