I'm using knitr and compiling my .Rnw file in Rstudio. Here's a MWE illustrating my issue. I want the code below to output "1, 2, 3" but instead it gives me "1, 1, 1".
%%%%%%%%%%%%%%%%
\documentclass[border=20pt]{standalone}
\usepackage{tikz}
\begin{document}
<<eval=TRUE, echo=FALSE, results='hide'>>=
faux.data<-c(1,2,3)
i<-1 # set loop index to 1
@
\begin{tikzpicture}
\foreach \x in {1,2,3}
{\node[draw, circle] at (\x,0) {\Sexpr{faux.data[i]}};
<<eval=TRUE, echo=FALSE, results='hide'>>=
i<-i+1 #advance loop index
@
}
\end{tikzpicture}
\end{document}
%%%%%%%%%%%%%%%%%
{\node[draw, circle] at (\x,0) {\Sexpr{toLatex(faux.data[i])}};
. See Is there any alternative to \Sexpr{} to write a matrix object in R?