Skip to content

preditc_table() fails to read table when there are missing data in the last column of the table #114

@ytorres-cambas

Description

@ytorres-cambas

If there are missing data in a variable located in the last column of the csv file created with hydrographr::get_predict_table(), get_predict_table() fails to read it when read = TREU. The error is something like: "Warning in fread(file.path(write_dir, "predict_table.csv")) :
Stopped early on line 186039. Expected 22 fields but found 21. Consider fill=TRUE and comment.char=. First discarded non-empty line: <<422482825,-0.717,2985,1888,3008,12756,470,1531,0,0,0,0,0,0,1169270656,0,-1,0,2,0,0>>". The error happens becasuse when the last value is missing, the final comma is also missing, so instead of ...,0,0, (empty last field), you just have ...,0,0 (no last field at all).

This can be solved if data.table::fread() is called in predict_table() as:
data.table::fread(
...
fill = TRUE,
na.strings = c("NA", "")
)

This stop fread() from aborting, give that “short” row an NA in the missing column, and read the rest of the file normally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions