Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

insert

Insert tag or extension into a file name


Description

This function inserts a tag or extension into a file name. It can also replace an element of a file name.

Usage

insert(x, ...)

## S3 method for class 'filename'
insert(x, tag = NULL, tag.pos = NULL, ext = NULL,
  ext.pos = NULL, replace = FALSE, ...)

## S3 method for class 'character'
insert(x, ...)

Arguments

x

file name (character or filename)

...

unused arguments

tag

one or more file name tags to insert

tag.pos

position at which to insert tag (NULL: append at the end or replace tag)

ext

one or more file extension tags to insert

ext.pos

position at which to insert extension (NULL: insert at penultimate position)

replace

if TRUE, tag or extension is replaced (default: replace last tag)

Details

By default, tags are inserted at the ultimate position and extensions at the penultimate position, if possible. (That is, the final file extension will not change, unless the insertion position is specified otherwise or the orginal file name had no extension.) If replace is TRUE, the tag at the indicated position is replaced by the new tag instead.

Value

modified object of the original type

Examples

f <- as.filename("data_expr_2014-05-01.tsv")

# new file name with inserted tags for saving normalized data
g <- insert(f, tag=c("mod", "norm"))
print(as.character(g))

# new file name with inserted extension for saving sorted data
h <- insert(f, ext="sorted")
print(as.character(h))

# new file name with different extension for saving in different format
i <- insert(f, ext="csv", replace=TRUE)
print(as.character(i))

# insert another tag
j <- insert(g, tag="qc", tag.pos=2)
print(as.character(j))

filenamer

Easy Management of File Names

v0.2.3
GPL (>= 3)
Authors
David J. H. Shih
Initial release
2018-05-01

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.