Debian Codegraph @

man/file_ext.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/paths.R
3 \name{file_ext}
4 \alias{file_ext}
5 \alias{sans_ext}
6 \alias{with_ext}
7 \title{Manipulate filename extensions}
8 \usage{
9 file_ext(x, extra = "")
10
11 sans_ext(x, extra = "")
12
13 with_ext(x, ext, extra = "")
14 }
15 \arguments{
16 \item{x}{A character of file paths.}
17
18 \item{extra}{Extra characters to be allowed in the extensions. By default,
19 only alphanumeric characters are allowed (and also some special cases in
20 \sQuote{Details}). If other characters should be allowed, they can be
21 specified in a character string, e.g., \code{"-+!_#"}.}
22
23 \item{ext}{A vector of new extensions. It must be either of length 1, or the
24 same length as \code{x}.}
25 }
26 \value{
27 A character vector of the same length as \code{x}.
28 }
29 \description{
30 Functions to obtain (\code{file_ext()}), remove (\code{sans_ext()}), and
31 change (\code{with_ext()}) extensions in filenames.
32 }
33 \details{
34 \code{file_ext()} is similar to \code{\link[tools:file_ext]{tools::file_ext()}}, and
35 \code{sans_ext()} is similar to \code{\link[tools:file_path_sans_ext]{tools::file_path_sans_ext()}}.
36 The main differences are that they treat \code{tar.(gz|bz2|xz)} and
37 \code{nb.html} as extensions (but functions in the \pkg{tools} package
38 doesn't allow double extensions by default), and allow characters \code{~}
39 and \verb{#} to be present at the end of a filename.
40 }
41 \examples{
42 library(xfun)
43 p = c("abc.doc", "def123.tex", "path/to/foo.Rmd", "backup.ppt~", "pkg.tar.xz")
44 file_ext(p)
45 sans_ext(p)
46 with_ext(p, ".txt")
47 with_ext(p, c(".ppt", ".sty", ".Rnw", "doc", "zip"))
48 with_ext(p, "html")
49
50 # allow for more characters in extensions
51 p = c("a.c++", "b.c--", "c.e##")
52 file_ext(p) # -/+/# not recognized by default
53 file_ext(p, extra = "-+#")
54 }