Skip to content

Fix problems() support for vroom_lines() output (#607) - #624

Closed
LeonidasZhak wants to merge 2 commits into
tidyverse:mainfrom
LeonidasZhak:fix/vroom-lines-problems-607
Closed

LeonidasZhak wants to merge 2 commits into
tidyverse:mainfrom
LeonidasZhak:fix/vroom-lines-problems-607

Conversation

@LeonidasZhak

Copy link
Copy Markdown

Fixes #607.

Problem

When vroom_lines() encounters a parsing issue, it warns users to call problems(). However:

  1. vroom_lines() discards the "problems" attribute when extracting the character column
  2. problems() only accepts tbl_df objects, rejecting character vectors

Fix

  • R/vroom_lines.R: Propagate the "problems" attribute from the tibble to the character vector when parsing errors exist
  • R/problems.R: Accept character vectors with a "problems" attribute; improve error messages for unsupported types
  • man/problems.Rd: Update @param x to document character vector support
  • tests/testthat/test-vroom_lines.R: Add tests for attribute propagation and error messages

Validation

R CMD INSTALL --no-docs --no-multiarch --no-test-load vroom
# vroom_lines tests: [ FAIL 0 | WARN 0 | SKIP 0 | PASS 19 ]
# problems tests: [ FAIL 1 | WARN 0 | SKIP 3 | PASS 51 ] (1 pre-existing failure)

The pre-existing failure at test-problems.R:132 is unrelated (vroom_materialize not found in test harness).

vroom_lines() extracts a character column from the tibble returned by
vroom_(), discarding the 'problems' attribute. This commit propagates
the attribute when parsing errors exist, and teaches problems() to
accept character vectors with a 'problems' attribute.

Fixes #607
The previous fix checked nrow(vroom_errors_(probs)) > 0 before
propagating the problems attribute. However, errors are populated
lazily during ALTREP vector materialization (element access), so
the check always found 0 errors at return time.

This fix propagates the problems attribute unconditionally when it
exists, matching how vroom() always carries the problems pointer.
The pointer is shared, so errors added during later materialization
are visible when problems() is called.

Also adds a regression test exercising the full round-trip:
vroom_lines() with embedded null → problems() returns the errors.
test_that("vroom_lines respects n_max", {
infile <- vroom_example("mtcars.csv")
expect_equal(vroom_lines(infile, n_max = 2), readLines(infile, n = 2))
expect_equal(vroom_lines(infile, n_max = 2), readLines(infile, n = 2), ignore_attr = "problems")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change
expect_equal(vroom_lines(infile, n_max = 2), readLines(infile, n = 2), ignore_attr = "problems")
expect_equal(
vroom_lines(infile, n_max = 2),
readLines(infile, n = 2),
ignore_attr = "problems"
)


test_that("vroom_lines uses na argument", {
expect_equal(vroom_lines(I("abc\n123"), progress = FALSE), c("abc", "123"))
expect_equal(vroom_lines(I("abc\n123"), progress = FALSE), c("abc", "123"), ignore_attr = "problems")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change
expect_equal(vroom_lines(I("abc\n123"), progress = FALSE), c("abc", "123"), ignore_attr = "problems")
expect_equal(
vroom_lines(I("abc\n123"), progress = FALSE),
c("abc", "123"),
ignore_attr = "problems"
)

vroom::vroom_write(df, f, append = TRUE)

expect_equal(vroom_lines(f), c("x\ty", "1\t2", "1\t2"))
expect_equal(vroom_lines(f), c("x\ty", "1\t2", "1\t2"), ignore_attr = "problems")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change
expect_equal(vroom_lines(f), c("x\ty", "1\t2", "1\t2"), ignore_attr = "problems")
expect_equal(
vroom_lines(f),
c("x\ty", "1\t2", "1\t2"),
ignore_attr = "problems"
)

vroom_write(data.frame(), file = tf, append = TRUE, delim = ",")

expect_equal(vroom_lines(tf, altrep = FALSE), c("a,b,c", "1,2,3"))
expect_equal(vroom_lines(tf, altrep = FALSE), c("a,b,c", "1,2,3"), ignore_attr = "problems")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change
expect_equal(vroom_lines(tf, altrep = FALSE), c("a,b,c", "1,2,3"), ignore_attr = "problems")
expect_equal(
vroom_lines(tf, altrep = FALSE),
c("a,b,c", "1,2,3"),
ignore_attr = "problems"
)

@LeonidasZhak

Copy link
Copy Markdown
Author

Withdrawing this because CI is currently failing and I should not ask maintainers to review an unready automated PR. I will only come back with a clean, focused change if useful. Sorry for the noise, and thank you for maintaining the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vroom_lines() warns about problems but problems() doesn't work on its output

1 participant