Skip to content

FR: in colClasses of fread, allow column names not present in actual table #1602

Description

@aushev

I often need to read multiple tables that share some (but not all) columns which would be passed to colClasses. It would be then convenient to make one vector with all those column names, i.e. instead of

chrcols1 <- c('colA', 'colB')
dt1 <- fread(file1, colClasses=list(character=chrcols1))
chrcols2 <- c('colA', 'colC')
dt2 <- fread(file2, colClasses=list(character=chrcols2))
# etc

use

chrcolsAll <- c('colA', 'colB', 'colC')
dt1 <- fread(file1, colClasses=list(character=chrcolsAll))
dt2 <- fread(file2, colClasses=list(character=chrcolsAll))

Right now this is not allowed ( "Column name '%s' in colClasses[[%d]] not found" ) but instead of throwing an error we could just exclude those column names from further processing.

Activity

  1. changed the title [-]FR: in colClasses, allow column names not found in actual table[/-] [+]FR: in colClasses of fread, allow column names not present in actual table[/+] on Mar 20, 2016
  2. gdmcdonald commented on Jul 24, 2019

    @gdmcdonald

    This would be a great feature!

  3. MichaelChirico commented on Jul 24, 2019

    @MichaelChirico
    Member

    In current dev, this is a warning (DTWARN), whereas in the linked commit it was an error (STOP).

    Is a warning too strict here? The idea is to relegate it to verbose output only? Or can we close this?

  4. gdmcdonald commented on Jul 25, 2019

    @gdmcdonald

    Ahhhhh yes the current dev solves all my problems! Thankyou

  5. ben-schwen commented on Oct 17, 2025

    @ben-schwen
    Member

    Current version implements this and warning seems like the right choice. Closing here, but feel free to reopen if the issue rearises or you feel that a warning is too much.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions