Skip to content

fread doesn't check colClasses to be valid type #1634

Description

@mattdowle
> sapply(fread("A,B\n1,2",colClasses="numeric"),class)   # ok
        A         B 
"numeric" "numeric" 
> sapply(fread("A,B\n1,2",colClasses="integer"),class)    # ok
        A         B 
"integer" "integer" 
> sapply(fread("A,B\n1,2",colClasses="string"),class)      # type "string" works?
          A           B 
"character" "character" 
> sapply(fread("A,B\n1,2",colClasses="c"),class)             
          A           B 
"character" "character" 
> sapply(fread("A,B\n1,2",colClasses="foo"),class)      # should be error that foo isn't valid type?
          A           B 
"character" "character" 
> 

Activity

  1. added this to the v1.9.8 milestone on Apr 7, 2016
  2. MichaelChirico commented on Apr 7, 2016

    @MichaelChirico
    Member

    maybe just produce a warning for all of the above?

  3. jangorecki commented on Jun 2, 2016

    @jangorecki
    Member

    how exactly we want to define valid type?

  4. modified the milestones: , v1.9.8 on Jul 21, 2016
  5. mattdowle commented on Jan 4, 2018

    @mattdowle
    MemberAuthor

    @jangorecki Looking at Hugh's PR #2545 made me realize the answer to your question. Just as read.csv, "foo" is a valid type to use in colClasses= if as.foo.character() or as.foo.default() exists. Otherwise, standard R error that as.foo method does not exist.

  6. MichaelChirico commented on Jan 8, 2018

    @MichaelChirico
    Member

    Whether as.* exists will be dependent on the local user's setup. I suppose this is a desired behavior -- users expecting coercion to foo class with methods defined in bar library can be trusted to handle loading bar themselves before running fread. From a glance at #2545, the backup (to use default interpretation, typically character) with a warning is probably ideal behavior -- if I forget to load bar, I'd rather be warned that the ex-post conversion was abandoned than to have fread fail.

  7. removed this from the milestone on May 10, 2018
  8. added this to the 1.12.4 milestone on May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions