Skip to content

na.strings for character vectors in fread #4263

Closed

Description

@aneudecker

The behaviour of na.strings seems to be inconsistent / faulty for columns with character and numeric contents. The values are quoted and separated by ";"

# Minimal reproducible example

content <- c(
  "\"@NULL@\";\"@NULL@\";\"@NULL@\";\"@NULL@\";\"@NULL@\"",
  "\"1\";\"2020-01-01\";\"2020-01-01 00:00:00\";\"3.14\";\"a\""
)

write(content, "test.csv")

data.table::fread(
  "test.csv",
  sep = ";",
  header = FALSE,
  na.strings = c("\"@NULL@\""),
  data.table = FALSE)

##   V1         V2                  V3   V4     V5
## 1 NA     @NULL@              @NULL@   NA @NULL@
## 2  1 2020-01-01 2020-01-01 00:00:00 3.14      a

Conversion works for values with numeric content but not for character content.

# Output of sessionInfo()

R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 19.04

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.8.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.8.0

locale:
 [1] LC_CTYPE=de_DE.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=de_DE.UTF-8        LC_COLLATE=de_DE.UTF-8    
 [5] LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=C             
 [7] LC_PAPER=de_DE.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.6.0    tools_3.6.0       data.table_1.12.8

Activity

  1. MichaelChirico commented on Nov 9, 2026

    @MichaelChirico
    Member

    Closed by #7068

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions