Sweaving the following:
\documentclass{article}
\begin{document}
<<>>=
x <- 5
y <- 10
@
The value of $z$ is \\
%\Sexpr{z}
\end{document}
generates the following error:
Error in eval(expr, envir, enclos) : object 'z' not found
Calls: <Anonymous> -> Sweave -> <Anonymous> -> eval -> eval
Execution halted
If \Sexpr{z}
is commented out, why is it causing an error?
This answer is a placeholder to record what I learned on my own. I will gladly accept a better one...
Sweave doesn't parse the LaTeX, so it will evaluate any \Sexpr
, even if it is commented out. So if you assigned a value to z
in the code chunk, %\Sexpr{z}
would print the value of z
. Amusingly, \Sexpr{#z}
will suppress the printing of the value of z
.
I also tracked down this (rather old) discussion of this issue in a mailing list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With