I have runoff data with a lot of zero values and occasionally some non-zero double values.
'readr::read_csv' guesses integer column type because of the many zeros.
How can I make read_csv to guess the correct double column type? I do not know the mapping of the variable names beforehand, hence I cannot give name-type mapping.
Here is a small example
# create a column of doubles with many zeros (runoff data)
#dsTmp <- data.frame(x = c(rep(0.0, 2), 0.5)) # this works
dsTmp <- data.frame(x = c(rep(0.0, 1e5), 0.5))
write_csv(dsTmp, "tmp/dsTmp.csv")
# 0.0 is written as 0
# read_csv now guesses integer instead of double and reports
# a parsing failure.
ans <- read_csv("tmp/dsTmp.csv")
# the last value is NA instead of 0.5
tail(ans)
Can I tell it to choose a try wider column types instead of issuing a parsing failure?
Issue 645 mentions this problem, but the workaround given there is on the writing side. I have little influence on the writing side.