I'm trying (as hard as i can) to create a script that will generate formatted word documents from plain text files using R language and reporteRs.
To extract text from one txt i'm using this code found on this thread Dealing with readLines() function in R :
fileName <- "C:/MyFolder/TEXT_TO_BE_PROCESSED.txt"
con <- file(fileName,open="r")
line <- readLines(con)
close(con)
Then add the extracted text to docx with this :
doc <- docx(template="temp.docx")
Next, adding the title (first line of the txt file)
doc <- addParagraph( doc, value = line[1], bookmark = "titre", stylename = "Titre")
then the body of the txt file
doc <- addParagraph( doc, value = line[2:length(line)], value = line[2:55], stylename = "Contenu")
Finally I create the docx
writeDoc(doc, file = "output-file.docx")
I want to be able to create a loop so I can generate multiple docx from multiple txt files. I will really appreciate your help