filename: Utilities for managing file names.

Description Usage Arguments Details Value Examples

View source: R/filename.R

Description

filename provides a S3 class to represent file names, which is inter-convertible with character.

This function creates a filename object with a file path, tags, extensions, date stamp or date-time stamp.

Usage

1
2
filename(x, path = NULL, tag = NULL, ext = NULL, date = NULL,
  time = NULL, subdir = TRUE)

Arguments

x

file name stem

path

path to the file

tag

tags for the file name

ext

file extension

date

date stamp (character or Date)

time

time stamp (character or POSIXct)

subdir

whether to append a date/time stamped subdirectory to path

Details

Either construct a filename object with the filename constructor or convert an existing file name from character to filename using as.filename. Then, manage the tags and extensions of the filename object with insert.

The functions set_fpath, set_fext, set_fdate, and set_ftime can be used on both character or filename to modify file names.

Use tag to quickly add or replace a tag on a file name (as a character or filename and coerce into a character.

The date and time parameters can be specified as character vectors or date/time objects. If time is given as a POSIXct, it will override date. If these parameters are both NULL, automated date and time stamping may be done and is controlled by getOption("filenamer.timestamp"). If this option is NULL, 0, or less, no date or time stamping will be done; if it is 1, only date stamping will be done; if it is 2 or greater, date-time stamping will be done (default). Set date or time to NA to suppress date or time stamping for a particular filename. Stamps are shown in ISO 8601 date format ( ( platforms and are thus omitted; hyphens are omitted from date-time stamps for brevity.

By default, a date stamped subdirectory is appended to the filepath. To disable this behaviour, set subdir to FALSE or disable path stamping globally by options(filenamer.path.timestamp = 0). This option is similar to filenamer.timestamp above.

Value

a filename object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# file name is date-time stamped and put in subdirectory by default
fn <- filename("data", tag="qc", ext="txt")
print(as.character(fn))

# disable date-time stamping and subdirectory insertion
fn2 <- filename("data", tag="qc", date=NA, time=NA, subdir=FALSE)
print(as.character(fn2))

# creating a new file name from an existing one yields a new time stamp
fn3 <- filename(fn)
print(as.character(fn3))

filenamer documentation built on May 4, 2018, 9:04 a.m.