I’m using the knitr package in R to try and convert a dataframe into a report.
The issue is that there is a lot of variability in the input data. The aim is to print one line of text (pulled from a dataframe, followed by a graph, also from a dataframe)
The following code is a pared down version of the same. It doesn’t output aby PDF file.
\documentclass{report}
\usepackage{forloop}
\newcounter{tmp}
\begin{document}
\newcommand{\Brep}{$\Sexpr{A}$}
\forloop{tmp}{1}{\value{tmp} < \Brep} {\Brep}
\end{document}
On checking logs, and removing portions, I’ve narrowed it down to knitr/latex not being able to evaluate the \FBrep portion in the forloop’s condition.
Is there any way to get around this?
Also, in the next step, I’ll need to use includegraphics in a similar manner, as follows
\includegraphics{\Brep.PNG}
Sorry if this is RTFM material. I’m really new, and I did look around a lot.
Thanks
You cannot let LaTeX call
knitrorR. Whatknitrdoes is to parse your document for R code, and evaluate the code. Then everything is completely done on R’s side, and you get a static LaTeX output document which has nothing to do with R anymore. So if you want to program anything, do it in R code.A direct translation of your program into R:
But it can be simplified to:
I also need to remind you that this may not be ideal approach to insert plots in your document (in general you do not need to take care of
\includegraphics{}). You need to be aware of the automation like this: