vroom icon indicating copy to clipboard operation
vroom copied to clipboard

Don’t overwrite existing file if appending an empty data frame

Open sbearrows opened this issue 1 year ago • 2 comments

Fixes tidyverse/readr#1408

Previously, if vroom_write() was supplied an empty data frame, vroom created an empty file without checking the value of append. But this meant data from the file could be deleted such as in this case.

library(vroom)
tf <- withr::local_tempfile()
data <- tibble::tibble(a = "1", b = "2", c = "3")

vroom_write(data, file = tf)
vroom(tf, show_col_types = FALSE)
#> # A tibble: 1 × 3
#>       a     b     c
#>   <dbl> <dbl> <dbl>
#> 1     1     2     3

vroom_write(data.frame(), file = tf, append = TRUE)
vroom(tf, show_col_types = FALSE)
#> # A tibble: 0 × 0

Created on 2022-07-15 by the reprex package (v2.0.1.9000)

sbearrows avatar Jul 16 '22 03:07 sbearrows

I recommend turning off altrep / lazy reading in this test.

jennybc avatar Aug 12 '22 16:08 jennybc

@jennybc I believe this is ready for another look!

sbearrows avatar Aug 12 '22 22:08 sbearrows