library(xfun)
p = c("abc.doc", "def123.tex", "path/to/foo.Rmd", "backup.ppt~", "pkg.tar.xz")
file_ext(p)
sans_ext(p)
with_ext(p, ".txt")
with_ext(p, c(".ppt", ".sty", ".Rnw", "doc", "zip"))
with_ext(p, "html")
# allow for more characters in extensions
p = c("a.c++", "b.c--", "c.e##")
file_ext(p) # -/+/# not recognized by default
file_ext(p, extra = "-+#")
Run the code above in your browser using DataLab