From 9cf58617dba4c79d6616050ecf84af35f683174b Mon Sep 17 00:00:00 2001 From: Brian Rice Date: Sat, 12 Sep 2020 12:18:09 -0500 Subject: [PATCH 1/3] Update tibble::data_frame to tibble::tibble tibble::data_frame is now deprecated but was still used for empty datasource connections. Fixes #1099 --- R/read_delim.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/read_delim.R b/R/read_delim.R index 53730be4..7b2c9801 100644 --- a/R/read_delim.R +++ b/R/read_delim.R @@ -193,14 +193,14 @@ read_delimited <- function(file, tokenizer, col_names = TRUE, col_types = NULL, if (is.connection(file)) { data <- datasource_connection(file, skip, skip_empty_rows, comment) if (empty_file(data[[1]])) { - return(tibble::data_frame()) + return(tibble::tibble()) } } else { if (!isTRUE(grepl("\n", file)[[1]]) && empty_file(file)) { return(tibble::tibble()) } if (is.character(file) && identical(locale$encoding, "UTF-8")) { - # When locale is not set, file is probablly marked as its correct encoding. + # When locale is not set, file is probably marked as its correct encoding. # As default_locale() assumes file is UTF-8, file should be encoded as UTF-8 for non-UTF-8 MBCS locales. data <- enc2utf8(file) } else { From 4389c11603e12748173a648bc491ba8ed78e1c8f Mon Sep 17 00:00:00 2001 From: Brian Rice Date: Sat, 12 Sep 2020 12:35:17 -0500 Subject: [PATCH 2/3] Add test for read_csv with empty csv files tibble::data_frame() is now deprecated. --- tests/testthat/test-read-csv.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/testthat/test-read-csv.R b/tests/testthat/test-read-csv.R index 112a2381..a07ddda3 100644 --- a/tests/testthat/test-read-csv.R +++ b/tests/testthat/test-read-csv.R @@ -184,6 +184,12 @@ test_that("empty file with col_names and col_types creates correct columns", { expect_equal(class(x$b), "integer") }) +test_that("empty file returns an empty tibble", { + file.create("foo.csv") + expect_equal(read_csv("foo.csv"), tibble::tibble()) + file.remove("foo.csv") +}) + # Comments ---------------------------------------------------------------- From 40b321199db6e00e763a43fd226ae170528f4bb8 Mon Sep 17 00:00:00 2001 From: Jim Hester Date: Mon, 14 Sep 2020 08:27:09 -0400 Subject: [PATCH 3/3] Add note to news --- NEWS.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index b77af06a..6e741a7e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -32,9 +32,7 @@ * New `%h` placeholder for parsing unrestricted hours (<0 and >23) to support parsing durations (#549, @krlmlr). -* Uses of `tibble::data_frame` updated to `tibble::tibble` -([tidyverse/dplyr#4069](https://github.com/tidyverse/dplyr/issues/4069), -@thays42) +* Uses of `tibble::data_frame` updated to `tibble::tibble` ([tidyverse/dplyr#4069](https://github.com/tidyverse/dplyr/issues/4069), @thays42, #1124, @brianrice2) * `read_delimited()` function return an empty `tibble::data_frame()` rather than signaling an error when given a connection for the `file` argument that