Learn R Programming

berryFunctions (version 1.15.0)

newFilename: 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, 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

Examples

Run this code

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

Run the code above in your browser using DataLab