Skip to content

na.strings="0" is not permitted in fread #2927

Description

@msgoussi

When I use fread, I get this error (NAstring <<0>> is recognized as type boolean, this is not permitted)
na.strings = c("", "-", "_", "..", "...", "--", "**", "" ,
"n/a", "n.a.", "#VALUE!", "0", "Inf", "-Inf", "NAN", "r", "e")

If I removed "0" from na.strings, fread is not getting error.

However, cells that contains "r" or "e", is not converted to NA, and their columns are characters.

Please advise.

Activity

  1. MichaelChirico commented on Jun 11, 2018

    @MichaelChirico
    Member

    Please include your data.table package version & system info, and the file itself, if you can.

  2. HughParsonage commented on Jun 11, 2018

    @HughParsonage
    Member
    data.table::fread("a,b,c\n0,1,2", na.strings = "0", verbose = TRUE)
    #> Input contains a \n or is "". Taking this to be text input (not a filename)
    #> [01] Check arguments
    #>   Using 12 threads (omp_get_max_threads()=12, nth=12)
    #> Error in data.table::fread("a,b,c\n0,1,2", na.strings = "0", verbose = TRUE):
    #>   freadMain: NAstring <<0>> is recognized as type boolean, this is not permitted.
  3. msgoussi commented on Jun 11, 2018

    @msgoussi
    Author

    Sys.info()
    sysname release version nodename
    "Windows" ">= 8 x64" "build 9200" "IRT-310677-Z440"
    machine login user effective_user
    "x86-64" "310677" "310677" "310677"

    data.table package: 1.11.4
    The file is so huge, it is almost 1.44 GB

  4. MichaelChirico commented on Jun 11, 2018

    @MichaelChirico
    Member

    Thank @HughParsonage, darn that looks no bueno.

    I guess there should be some interaction with logical01 but there doesn't appear to be.

  5. added this to the 1.11.6 milestone on Jun 11, 2018
  6. msgoussi commented on Jun 11, 2018

    @msgoussi
    Author

    Is it a bug?

  7. jangorecki commented on Jun 11, 2018

    @jangorecki
    Member

    @msgoussi yes, you can workaround it with something like

    data.table::fread("a,b,c\n0,1,2")[a==0, a:=NA]
  8. msgoussi commented on Jun 11, 2018

    @msgoussi
    Author

    If i have 500 columns and i need to clean columns and consider the following strings , c("", "-", "_", "..", "...", "--", "**", "" ,
    "n/a", "n.a.", "#VALUE!", "0", "Inf", "-Inf", "NAN", "r", "e"), as na. The way around will not look good. This is my opnion

  9. MichaelChirico commented on Jun 11, 2018

    @MichaelChirico
    Member
  10. modified the milestones: 1.11.6, 1.12.0 on Sep 20, 2018
  11. modified the milestones: 1.12.0, 1.12.2 on Jan 11, 2019
  12. changed the title [-]na.strings in fread [/-] [+]na.strings="0" is not permitted in fread[/+] on Jan 11, 2019
  13. removed this from the 1.12.2 milestone on Jan 14, 2019
  14. ribailey commented on Jul 3, 2020

    @ribailey

    I have an R package on Github, ribailey/gghybrid, which includes a function to read genomic data files with potentially millions of columns, and one of the main softwares for producing these input files, PLINK, always codes missing data as zero. I use fread within my function to read in the data and declare missing values. This means I can't read in the most common file type people might want to use, due to the bug described here. Has there been any progress on this? Many thanks, Richard.

  15. ben-schwen commented on Oct 12, 2020

    @ben-schwen
    Member

    Removing || strcmp(ch,"1")==0 || strcmp(ch,"0")==0 from fread.c seems like an option to "fix" this.

    Only breaks 1 test case which is explicitly testing for na.strings = '1'.

    Interaction with logical01 seems also legit.

    data.table::fread("a,b,c\n0,1,2\n1,0,2", na.strings = "0", logical01=T)
    
            a      b     c                                                                                                     
        <lgcl> <lgcl> <int>                                                                                                  
    1:     NA   TRUE     2                                                                                                  
    2:   TRUE     NA     2 
    
  16. shrektan commented on Oct 12, 2020

    @shrektan
    Member

    I think the expected behavior is that we should not allow logical01=TRUE and na.strings = "0" at the same time. If this is agreed, I'm happy to start to file a PR for this.

  17. MichaelChirico commented on Oct 13, 2020

    @MichaelChirico
    Member

    Agreed @shrektan. Nor na.strings = "1" though I guess that's a pretty obscure use case.

  18. self-assigned this
    on Oct 20, 2020
  19. added this to the 1.14.3 milestone on Oct 15, 2021
  20. modified the milestones: 1.14.9, 1.15.0 on Oct 29, 2023
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