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 doesn't check colClasses to be valid type #1634

Closed
mattdowle opened this issue Apr 7, 2016 · 4 comments · Fixed by #2545
Closed

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

mattdowle opened this issue Apr 7, 2016 · 4 comments · Fixed by #2545
Assignees
Milestone

Comments

@mattdowle
Copy link
Member

> 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" 
> 

@mattdowle mattdowle added the bug label Apr 7, 2016
@mattdowle mattdowle added this to the v1.9.8 milestone Apr 7, 2016
@MichaelChirico
Copy link
Member

maybe just produce a warning for all of the above?

@jangorecki
Copy link
Member

how exactly we want to define valid type?

@arunsrinivasan arunsrinivasan modified the milestones: v2.0.0, v1.9.8 Jul 21, 2016
HughParsonage added a commit to HughParsonage/data.table that referenced this issue Jan 3, 2018
HughParsonage added a commit to HughParsonage/data.table that referenced this issue Jan 3, 2018
@mattdowle
Copy link
Member Author

@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.

@MichaelChirico
Copy link
Member

MichaelChirico commented Jan 8, 2018

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.

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

Successfully merging a pull request may close this issue.

4 participants