Skip to content

Commit

Permalink
Make read_line more robust in conjunction with skip_blank_rows
Browse files Browse the repository at this point in the history
Fixes #968
  • Loading branch information
jimhester committed Sep 14, 2020
1 parent b01ae1e commit e675e0a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

## Additional features and fixes

* `read_lines(skip_empty_rows = TRUE)` no longer crashes if a file ends with an empty line (#968)

* `write_*()` functions gain a `eol =` argument to control the end of line character used (#857). This allows writing of CSV files with Windows newlines (CRLF) if desired.

* `write_excel_csv()` no longer outputs a byte order mark when appending to a file (#1075).
Expand Down
2 changes: 1 addition & 1 deletion src/TokenizerLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TokenizerLine : public Tokenizer {
if (!moreTokens_)
return Token(TOKEN_EOF, line_, 0);

while (cur_ != end_) {
while (cur_ < end_) {
Advance advance(&cur_);

if (*cur_ == '\0')
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-read-lines.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ test_that("allocation works as expected", {
expect_equal(length(read_lines(tmp)), 2^11)
})

test_that("read_lines(skip_empty_rows) works when blank lines are at the end of the file (#968)", {
tmp <- tempfile()
on.exit(unlink(tmp))

writeLines(con = tmp,
"test
")

expect_equal(read_lines(tmp, skip_empty_rows = TRUE), "test")
})

# These tests are slow so are commented out
#test_that("long vectors are supported", {
#tmp <- tempfile(fileext = ".gz")
Expand Down

0 comments on commit e675e0a

Please sign in to comment.