I have written a for loop in LaTeX using the forloop package, and on each iteration, I would like to use a different subset of a vector that is defined in an R chunk above. However, each iteration of the loop resets the counter back to its starting value before the code within the loop. Below is an example:
```{r}
n <- 3
count <- 1
vec <- c("A","B","C")
```
\newcounter{i}
\forloop{i}{0}{\value{i} < `n`}{
```{r}
print(vec[count])
```
```{r}
count <- count + 1
```
}
I desire A B C as my output, but instead, the counter is reset and I get A A A.
Is there a way to define the R variable as global and prevent it from resetting upon the next iteration, or is there a way to use the LaTeK counter in the R chunk?
Thank you!