How to fwrite NA values as empty, not empty quotes

Viewed 674

When I fwrite to csv, I am getting empty quotes for NA values

I would prefer nothing at all

Here is the csv

# csv_in
1,2,,3
4,5,Dave,6
x = fread(csv_in)
fwrite(x, path.csv)

# Output
# 1,2,"",3
# 4,5,Dave,6

# Desired output
# 1,2,,3
# 4,5,Dave,6

I cannot find any way of setting na = to get this output

EDIT

The dput is a clue to the issue

# csv_in
1,2,,3
4,5,Dave,6

structure(list(V1 = c(1L, 4L), V2 = c(2L, 5L), V3 = c("", "Dave"
), V4 = c(3L, 6L)), row.names = c(NA, -2L), class = c("data.table", 
"data.frame"), .internal.selfref = <pointer: 0x0000000000111ef0>)

# csv_in_alternative
1,2,,3
4,5,,6

structure(list(V1 = c(1L, 4L), V2 = c(2L, 5L), V3 = c(NA, NA), 
    V4 = c(3L, 6L)), row.names = c(NA, -2L), class = c("data.table", 
"data.frame"), .internal.selfref = <pointer: 0x0000000000111ef0>)

Still don't know how to control this behaviour however

1 Answers

add quote=F

fwrite(x, path.csv, quote=F)
Related