davidgohel / ReporteRs

Note that ReporteRs has been removed from CRAN the 16th of July 2018 and is not maintained anymore. please migrate to officer.
245 stars 44 forks source link

For Loops to create different docx files with ReporteRs #203

Closed William8750 closed 7 years ago

William8750 commented 7 years ago

I'm having some trouble with the creation of a for loop with ReporteRs. The problem: I have a folder with several .png figures. Every patients have 2 figures and I would like to create a docx document (from a template) for every patients, thus a word file with two figures side-by-side.

My solution (but it does not work as i would like): I create a list with the name of patients file

fl=c("Patient1.L2.png","Patient1.L5.png","Patient2.L2.png","Patient2.L5.png") file_names = c() for (i in 1:length(fl) { file_names[i] = list.files(pattern=fl[i]) }

file_names [1] "Patient1.L2.png" "Patient1.L5.png" "Patient2.L2.png" "Patient2.L5.png"

Then I tried to create a for loop but it does not work at all. I would like that it creats as much docx as the number of patients (so in my example two words file) where have in first file only Patient1 images and then only patient2 figures in another word document.

Is there a way? thank you to everyone who whill help

davidgohel commented 7 years ago

In the body of your for loop, you should:

  1. create a docx object
  2. Use addImage function twice, for each call provide argument filename (filename of image 1 and filename of image 2)
  3. use writeDoc to generate the document for patient X.
William8750 commented 7 years ago

really thank you for you patience and help My problem is in the second step how to call differently in the for loop two files

davidgohel commented 7 years ago

did you read the documentation?

William8750 commented 7 years ago

Hi David, do you mean the manual of ReporteRs?

davidgohel commented 7 years ago

I mean ?addImage

William8750 commented 7 years ago

ah yes of course!!!

davidgohel commented 7 years ago

Can you be more specific about what is the issue with ReporteRs? What error do you get? Do you have a reproducible example? Are you really facing an issue with ReporteRs or are you asking help for writing a for loop?