increment_file_version: If a file exists, get a new path with 'v1', 'v2', etc....

View source: R/utils_io.R

increment_file_versionR Documentation

If a file exists, get a new path with 'v1', 'v2', etc. appended

Description

If file does not exist, return the original path

Usage

increment_file_version(outpath)

Arguments

outpath

[chr] full path to file

Value

[chr] new path with version number appended (if necessary)

Examples

dir.create(tempdir(), recursive = TRUE, showWarnings = FALSE)
fname_old <- "test_file.csv"
file.create(file.path(tempdir(), fname_old))
list.files(tempdir()) # [1] "test_file.csv"
fname_new <- increment_file_version(file.path(tempdir(), "test_file.csv"))
file.create(fname_new)
list.files(tempdir()) # 1] "test_file_v1.csv" "test_file.csv"
file.remove(c(file.path(tempdir(), fname_old), fname_new))

epi-sam/SamsElves documentation built on June 12, 2025, 7 a.m.