fileNameFactory: A function factory to create a function that is used to...

View source: R/fileNameFactory.R

fileNameFactoryR Documentation

A function factory to create a function that is used to create a file name with a certain extention.

Description

A function factory to create a function that is used to create a file name with a certain extention.

Usage

fileNameFactory(path = "Rdata", extension = ".Rdata", createFolder = TRUE)

Arguments

path

the path that is concatenated to a file name.

extension

the file extension that is concatenated to a file name.

createFolder

logical, whether to create the folder if the path doesn't exist.

Value

fileNameFactory returns a function that create a file name. That function has two attributs, i.e., 'path' and 'extension'

Examples

## Not run: 
Rdata = fileNameFactory(path = "Rdata/", ".Rdata")
Rdata
Rdata("asdf")

x = 10
pngs = fileNameFactory("figs/", ".png")
pngs
pngs("pngFig", x)

pdfs = fileNameFactory("pdfs/", ".png")
pdfs
pdfs("first/", "pngFile_", x)

# Once the function is created, the path/extension will not be changed by changing the attributes
attr(pngs, "path") = "figs_2"
pngs
pngs("asdf")
# You need to recreate the function with the new path
pngs2 = fileNameFactory("figs_2/", ".png")
pngs2("asdf")

## End(Not run)

paodan/funcTools documentation built on April 1, 2024, 12:01 a.m.