vroom
vroom copied to clipboard
Don’t overwrite existing file if appending an empty data frame
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)
I recommend turning off altrep / lazy reading in this test.
@jennybc I believe this is ready for another look!