newFilename

0th

Percentile

Create new filename if file already exists

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

Keywords
file
Usage
newFilename(filename, ignore = FALSE, pre = "", mid = "\n  ", end = "",
  quiet = FALSE, ntrunc = 3)
Arguments
filename
Char (vector): file name(s).
ignore
Logical (vector, recycled): Ignore file? DEFAULT: FALSE
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.

See Also

file.exists

Aliases
  • newFilename
Examples

fns <- c("data", "stupiddummy", "ExampleGraph.png", "berryFunctions.Rproj", 
         "README.md", "stupiddummy.txtdude", "DESCRIPTION", "test_devel.R")
newFilename(fns)
newFilename(fns, ignore=TRUE)
newFilename(fns, ignore=rep(0:1, each=4))
newFilename(fns, ntrunc=2)
newFilename("README.md")
newFilename("dummy", mid="") # no line break

Documentation reproduced from package berryFunctions, version 1.15.0, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.