newFilename: Create new filename if file already exists

View source: R/newFilename.R

newFilenameR Documentation

Create new filename if file already exists

Description

Check if files already exist and append _1 or _2, etc to the filename if needed, thereby giving useful messages.

Usage

newFilename(
  filename,
  ignore = FALSE,
  overwrite = FALSE,
  tellignore = TRUE,
  pre = "",
  mid = "\n",
  end = "",
  quiet = FALSE,
  ntrunc = 3
)

Arguments

filename

Char (vector): file name(s).

ignore

Logical (vector, recycled): Ignore file? DEFAULT: FALSE

overwrite

Logical (vector, recycled): overwrite file? DEFAULT: FALSE

tellignore

Logical: Message about ignored files? DEFAULT: TRUE

pre, mid, end

Char: strings to append after traceback / message / filenames. DEFAULT: "", "\n ", ""

quiet

Logical: Suppress messages about creating file(s)? DEFAULT: FALSE

ntrunc

Integer: Number of filenames printed in messages before they get truncated with message "(and xx more)". DEFAULT: 3

Value

newFilename returns the input with an added "_n" in the filename for each file that already existed.

Author(s)

Berry Boessenkool, berry-b@gmx.de, Oct 2016 + Jan 2017

See Also

file.exists

Examples


fns <- c("dummy1", "dummy2.txt", "berryFunctions.Rproj",
         "README.md", "dummy2.dummy", "DESCRIPTION", "dummy4.R", "dummy5")
newFilename(fns)
newFilename(fns, ignore=TRUE)
newFilename(fns, ignore=rep(c(TRUE,FALSE), each=4) )
newFilename(fns, ignore=rep(c(TRUE,FALSE), each=4), tellignore=FALSE)
newFilename(fns, ntrunc=2)
newFilename(fns, overwrite=TRUE, ign=c(TRUE,TRUE,rep(FALSE,6)))
newFilename("README.md")
newFilename("dummy", mid=" ") # no line break


berryFunctions documentation built on May 29, 2024, 4:01 a.m.