Description Usage Arguments Details Value Author(s) See Also Examples
View source: R/stripExtension.R
Remove the extension of a vector of filenames, assuming that the extension is the set of characters
that follows the last "."
1 | stripExtension(vec, split.char = ".")
|
vec |
Character vector (usually containing filenames) |
split.char |
A single character used to split the character strings |
Assumes paths are delineated using forward slashes. If an NA
is
supplied, then an NA
is returned. If the desired string doesn't
exist (see examples below), a ""
is returned.
Character vector with the last "." and the filename extension removed. Alternatively, another split character could be used.
Landon Sego
Additional functions for filename manipulations: getExtension
, stripPath
,
getPath
, grabLast
, basename
, dirname
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | stripExtension(c("this old file.doc", "that young file.rtf",
"this.good.file.doc", "this_bad_file"))
stripExtension(c("this old file*doc", "that young file*rtf",
"this*good*file*doc", "this_bad_file"), split.char = "*")
# Named vectors are not required, but are included here to make the
# output easier to read. This example demonstrates a number of
# pathological cases.
stripExtension(c(a = NA, b = ".doc", c = "this.pdf", d = "this.file.", e = ".",
f = "noExtension", g = "direc.name/filename.txt", h = ""))
# An example with 'real' files
files <- dir(file.path(path.package(package = "Smisc"), "data"), full.names = TRUE)
print(files)
stripExtension(files)
stripExtension(stripPath(files))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.