こここんにちは可能な答えですが、私は代わりに、データフレームのリストに結果を格納していますが、あなたは(rbind.data.frame、結果)
をdo.call使用して一方から他方に変換することができます
require(stringr)
datawd<-"C:/my/path/to/folder/" # your data directory
listoffiles<-list.files(str_c(datawd)) # list of files
listoffiles<-listoffiles[grep(".txt",listoffiles)] # only extract .txt files
my_paths<-str_c(datawd,listoffiles) # vector of path
# the following works with windows only
progress<-winProgressBar(title = "loading text files",
label = "progression %",
min = 0,
max = length(my_paths),
initial = 0,
width = 400)
#000000000000000000000000000000000000000 loop
for (i in 1:length(chemins)){
result<-list()
setWinProgressBar(progress,i,label=listoffiles[i])
the_date<-sapply(strsplit(listoffiles[i],"_"),"[[",1)
the_theme<-sapply(strsplit(listoffiles[i],"_"),"[[",2)
the_source<-sapply(strsplit(listoffiles[i],"_"),"[[",3)
# open connexion with read
con <- file(my_paths[i], open = "r")
# readlines returns an element per line, here I'm concatenating all,
#you will do what you need....
the_text<- str_c(readLines(con,warn = FALSE))
close(con) # closing the connexion
result[[i]]<-list()
result[[i]]["date"]<-the_date
result[[i]]["source"]<-the_source
result[[i]]["theme"]<-the_theme
result[[i]]["text"]<-the_text
}
#000000000000000000000000000000000000000 end loop
'list.files'とパッケージ' readr'を調べてください – CPak