I'm reading multiple .txt files using list.file()
and file.path()
. Just wanted to parse the full path names and extract the portion after the last “/” and before the “.”
Here is the structure of file path names :
"C:/Users/Alexandre/Desktop/COURS/FORMATIONS/THESE/PROJET/RESULTATS/Vessel features/Fusion/OK/SAT-DPL192C.txt"
The code I've tried
# l <- list.files(pattern = "SAT(.+)*.txt")
# f <- file.path(getwd(), c=(l))
f <- c("C:/Users/Alexandre/Desktop/COURS/FORMATIONS/THESE/PROJET/RESULTATS/Vessel features/Fusion/OK/SAT-DPL192C.txt", "C:/Users/Alexandre/Desktop/COURS/FORMATIONS/THESE/PROJET/RESULTATS/Vessel features/Fusion/OK/SAT-DPL193D.txt")
d <- lapply(f, read.delim)
names(d) <- gsub(".*/(.*)..*", "1", f)
Last string give [1] "1" "1"
instead of [1] "DPL192C" "DPL193D"
etc...
I've also tried the syntax like ".*/(.+)*..*
for the portion to conserv with same result.
gsub(".*([^/]+)\\..*","\\1",f)