fread: need more flexible behavior when encountering a broken line.

Open
#2,263 6 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Start at the fread entry point and trace the existing fill=TRUE handling for lines with inconsistent field counts. Define coverage for the proposed error, fill, skip, and extract strategies, including report output and the extract fields lineno, rowno, line, and nfields; done means each mode has tested, consistent behavior.

Written by the indexing model from the issue text.

Description

feature request fread

A new parameter bad.lines (or similar) is proposed. This parameter adjusts fread's strategy when dealing with lines that are "broken" (i.e. have less or more than the required number of columns). This parameter may take the following values:

  • "error" (default) -- stop scanning the file and raise an exception.
  • "fill" (currently achieved with fill=TRUE) -- any lines having too few fields are padded with NAs. Here "too few" means less than the maximum number of fields observed across all rows in the file.
  • "skip" -- broken lines are simply ignored.
  • "extract" -- any broken lines are placed into a separate datatable, whereas the "main" datatable retains empty rows in their place. The extra datatable will have at least the following fields: lineno (line number in the original data file), rowno (corresponding row number in the "main" datatable), line (the text of the line), nfields (number of fields detected on that line)

Additionally, there should be parameter report (default FALSE), which is used for strategies "fill" and "skip", and instructs fread to report to the user line numbers that were filled/skipped.

Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.