1

I have saved the 2 images below into my working directory named bl_convergence_acorr001.png and bl_convergence_acorr002.png respectively. My goal is to add those images in a word document. But the number of images may not be static like this example but dynamic. So my thought was to create a list in which those names will be saved. The same logic must be applied for the titles as well. The first should be named Figure 1, the second Figure 2 etc. How can I pass the code that adds the image inside the for() loop?

1st. enter image description here 2nd. enter image description here

 ---
title: "My Title"
author: "Me"
date:  "1/1/2016"
output: bookdown::word_document2
---


```{r cars, echo=FALSE,fig.cap = ". (m_BARI_POP1_3_PRIMARY_12_ACR20_independent_fixed_fixed, logit_independent_fixed_fixed) Baseline Autocorrelation plots"}
knitr::include_graphics("bl_convergence_acorr001.png")

```


```{r cars2, echo=FALSE,fig.cap = ". (m_BARI_POP1_3_PRIMARY_12_ACR20_independent_fixed_fixed, logit_independent_fixed_fixed) Baseline Trace plots"}
knitr::include_graphics("bl_convergence_acorr002.png")
```
firmo23
  • 7,490
  • 2
  • 38
  • 114
  • You could assign the figure number to a variable and (echo off - R code) to increase the the figure counter. – GWD Mar 14 '19 at 14:31
  • How can I put *Figure 1* ![](bl_convergence_acorr001.png) inside the r code chunk? – firmo23 Mar 14 '19 at 15:09
  • 1
    have alook at https://stackoverflow.com/questions/37116632/r-markdown-html-number-figures ... even better imho – GWD Mar 14 '19 at 15:35
  • I have editted my Q thanks to your comment but the issue of the dynamic numbers of iterations remains. – firmo23 Mar 14 '19 at 16:05
  • Where would you put the for loop? Is building an R code file where the FOR looping is then done an option? I did that on some occasions … – GWD Mar 14 '19 at 19:04
  • Normally around each one of the r code chunks cars and cars2 – firmo23 Mar 14 '19 at 19:13
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/190044/discussion-between-wd11-and-firmo23). – GWD Mar 14 '19 at 19:28

0 Answers0