Extract file extension from file path
Solution 1:
This is the sort of thing that easily found with R basic tools. E.g.: ??path.
Anyway, load the tools
package and read ?file_ext
.
Solution 2:
Let me extend a little bit great answer from https://stackoverflow.com/users/680068/zx8754
Here is the simple code snippet
# 1. Load library 'tools'
library("tools")
# 2. Get extension for file 'test.txt'
file_ext("test.txt")
The result should be 'txt'.
Solution 3:
simple function with no package to load :
getExtension <- function(file){
ex <- strsplit(basename(file), split="\\.")[[1]]
return(ex[-1])
}