insert: Insert tag or extension into a file name

Description Usage Arguments Details Value Examples

View source: R/insert.R

Description

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

Usage

1
2
3
4
5
6
7
8
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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 documentation built on May 4, 2018, 9:04 a.m.