extname: Get the base and extension(s) of file name(s)

Description Usage Arguments Value Note Author(s) Examples

View source: R/extname.R

Description

Many files have base and extensions in their names, for instance for the file mybook.pdf, the base is mybook and the extension is pdf. basefilename extname functions extract these information from one or more file names.

Usage

1
extname(x, ifnotfound = NA, lower.case = FALSE)

Arguments

x

Character vector of file names; other classes will be coereced to characters

ifnotfound

If no extension name was found, the value to be returned. Default is NA

lower.case

Logical, should the names returned in lower case?

Value

The base file name or the extension as characters, of the same length as the input file name character. In case that a file name does not contain a extension, NA will be returned.

Note

In case there are multiple dots in the input file name, the last field will be taken as the extension, and the rest as the base name. For instance for file test.out.txt, returned base name is test.out and extension is txt.

Author(s)

Jitao David Zhang <jitao_david.zhang@roche.com>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
extname("mybook.pdf")
extname("sequence.in.fasta")
extname(c("/path/mybook.pdf", "test.doc"))
extname("README")
extname("README", ifnotfound="")
extname("/path/my\ home/Holiday Plan.txt")

basefilename("mybook.pdf")
basefilename("sequence.in.fasta")
basefilename(c("/path/mybook.pdf", "test.doc"))
basefilename("README")
basefilename("/path/my\ home/Holiday Plan.txt")

basefilename("myBook.pdf", lower.case=TRUE)
extname("myBook.PDF", lower.case=TRUE)

ribiosUtils documentation built on March 13, 2020, 2:54 a.m.