I understand from this question that it's possible to push a variable to an Rnw file from the R script that calls it by storing that variable in the global environment within the R script. I've tried to do that but I can't get the Sweave file to recognize the variable.
For example, if I have an R script (say, test.R
) that looks like:
TESTGLOBALVARIABLE <<- "XXXXXXXXXTESTGLOBALVARIABLEXXXXXXXXXXX"
system("R CMD Sweave /foo/bar/test.Rnw"))
and test.Rnw
looks like:
\documentclass{article}
\usepackage[absolute]{textpos}
\setlength{\TPHorizModule}{30mm}
\setlength{\TPVertModule}{\TPHorizModule}
\textblockorigin{10mm}{10mm} % start everything near the top-left corner
\setlength{\parindent}{0pt}
\begin{document}
\begin{textblock}{3}(0,0)
The test global variable is: \Sexpr{TESTGLOBALVARIABLE}
\end{textblock}
\begin{textblock}{2}(2,1)
\textblocklabel{block two}
Here is another, slightly narrower, block, at position (2,1) on the page.
\end{textblock}
\end{document}
When I run test.R, I get an error Error: at test.Rnw:13, object 'TESTGLOBALVARIABLE' not found
Execution halted
.
I've checked similar questions like this one. Is it possible to do this without brew?