I am trying to use readr::read_fwf to read-in a .txt file. I know all of the column widths but I receive this parsing error which I do not know how to resolve:
fwf_widths <- c(12, 2, 6, ...)
fwf_names <- c("V1", "V2", "V3", ...)
col_types <- c("ccc...")
df <- read_fwf(file = file, fwf_widths(fwf_widths, fwf_names),
col_types = col_types)
Warning: 1 parsing failure.
row col expected actual file
372722 description embedded null /path/to/my/file.txt
I've tried adding trim_ws = T which does not get rid of the error. I looked at the actual contents of df[372722, ] and it looks like description contains the correct contents. Can someone please help me interpret what embedded null means and how I can potentially deal with this issue?
One of the bytes in your fwf is a zero-value byte, which is illegal in an R character string. If you just remove it you will destroy the alignment of the subsequent entries in the fwf, so you need to replace it. The following function will write a space character by default at any zero byte locations.
Please back up your .fwf file before using this.
Now you just need to do
and then your own code should work. If it doesn't, your fwf must be corrupted.