Skip to contents

Save comma separated value files, if file exists, backup original file.

Usage

safe_write_csv(x, file, ..., quiet = FALSE)

Arguments

x, file, ...

pass to write.csv

quiet

whether to suppress overwrite message

Value

Normalized path of file

Examples


f <- tempfile()
x <- data.frame(a = 1:10)

# File not exists, same as write file, returns normalized `f`
safe_write_csv(x, f)
#> [1] "/private/var/folders/c9/jqpw9nhs7jj7vm5185nyw05h0000gn/T/Rtmph6Cicq/file181566e2076f"

# Check whether file exists
file.exists(f)
#> [1] TRUE

# write again, and the old file will be copied
safe_write_csv(x, f)
#> [1] "/private/var/folders/c9/jqpw9nhs7jj7vm5185nyw05h0000gn/T/Rtmph6Cicq/file181566e2076f"