Skip to content

fread's na.strings argument should handle values like "-999" #1314

@arunsrinivasan

Description

@arunsrinivasan

With @dselivanov's excellent PR, providing na.strings value doesn't result in columns being coerced to character anymore.

There's still one point left to address though, as mentioned under that PR -- cases like these:

require(data.table)
DT = data.table(a=9:10, b=9:10 + 0.1, c=as.logical(0:1))
text = do.call("paste", c(DT, collapse="\n", sep=","))
ans1 = fread(text, na.strings=c("9", "9.1", "FALSE"))
#    V1   V2    V3
#1:  9  9.1 FALSE
#2: 10 10.1  TRUE

sapply(ans1, class)
#         V1        V2        V3 
#  "integer" "numeric" "logical" 

# whereas read.table() gives
ans2 = read.table(text=text, na.strings=c("9", "9.1", "FALSE"), sep=",", header=FALSE)
#   V1   V2   V3
#1 NA   NA   NA
#2 10 10.1 TRUE

sapply(ans2, class)
#         V1        V2        V3 
#  "integer" "numeric" "logical" 

read.table() handles them correctly.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions