Learn R Programming

this.path (version 1.2.0)

ext: File Extensions

Description

splitext splits an extension from a path.

removeext removes an extension from a path.

ext gets the extension of a path.

ext<- sets the extension of a path.

Usage

splitext(path, compression = FALSE)
removeext(path, compression = FALSE)
ext(path, compression = FALSE)
ext(path, compression = FALSE) <- value

Value

for splitext, a matrix with 2 rows and length(path) columns. The first row will be the roots of the paths, the second row will be the extensions of the paths.

for removeext and ext, a character vector the same length as path.

for ext<-, the updated object.

Arguments

path

character vector, containing path names.

compression

should compression extensions ‘.gz’, ‘.bz2’, and ‘.xz’ be taken into account when removing/getting an extension?

value

a character vector, typically of length 1 or length(path), or NULL.

Details

tilde expansion of the path will be performed.

Trailing path separators are removed before dissecting the path.

It will always be true that path == paste0(removeext(path), ext(path)).

Examples

Run this code
splitext(character(0))
splitext("")

splitext("file.ext")

splitext(c("file.tar.gz", "file.tar.bz2", "file.tar.xz"), compression = FALSE)
splitext(c("file.tar.gz", "file.tar.bz2", "file.tar.xz"), compression = TRUE)

x <- "this.path_1.0.0.tar.gz"
ext(x) <- ".png"
x

x <- "this.path_1.0.0.tar.gz"
ext(x, compression = TRUE) <- ".png"
x

Run the code above in your browser using DataLab