insert {filenamer} | R Documentation |
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 ( |
... |
unused arguments |
tag |
one or more file name tags to insert |
tag.pos |
position at which to insert tag
( |
ext |
one or more file extension tags to insert |
ext.pos |
position at which to insert extension
( |
replace |
if |
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 original 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))