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?
"/foo/bar/test.R"script that calls theR CMD Sweavecommand, obviously it hangs. But I'll try sourcing it from a different R script. – wtrs Mar 01 '18 at 14:12R CMD Sweavecommand, but that defeats the purpose. If I create another script (say,/foo/bar/set_vars.R) with only theTESTGLOBALVARIABLE <<- "XXXTESTGLOBALVARIABLEXXXX"line, that wouldn't work either, because I need to set the value ofTESTGLOBALVARIABLEwithintest.R, so I can't have it hardcoded inset_vars.R. If there is some way to editset_vars.Rwithintest.R, that could work. I'll play around withfile.edit()and see if I can get it to work. – wtrs Mar 01 '18 at 14:42