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/1y/56hdyx6x0_jb18k7b4ys9b6w0000gn/T/RtmpFQqvoC/file1c961e8c80b"

# 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/1y/56hdyx6x0_jb18k7b4ys9b6w0000gn/T/RtmpFQqvoC/file1c961e8c80b"