tidyverse / vroom

Fast reading of delimited files
https://vroom.r-lib.org
Other
621 stars 60 forks source link

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

Closed sbearrows closed 2 years ago

sbearrows commented 2 years ago

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)

jennybc commented 2 years ago

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

sbearrows commented 2 years ago

@jennybc I believe this is ready for another look!