getExtension {Smisc} | R Documentation |
Get the extension of a vector of filenames, assuming that the extension is the set of characters that
follows the last "."
. A wrapper for grabLast
.
getExtension(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 of filename extensions
Landon Sego
Additional functions for filename manipulations: stripExtension
, stripPath
,
getPath
, grabLast
, basename
, dirname
getExtension(c(a = "this old file.doc", b = "that young file.rtf", c = "this.good.file.doc", d = "this_bad_file", e = "thisfile.", f = NA, g = "that.this.pdf", h = ".", i = "")) # An example with 'real' files files <- dir(file.path(path.package(package = "Smisc"), "data"), full.names = TRUE) print(files) getExtension(files)