0

I want to use tikz to implement basic graphics in an automated report created by Sweave. Therefore, I created an R function, returning the tikz command, based on the data. My code looks similar to this:

<<echo=FALSE>>=
y <- 20
code <- cat(paste("\\draw (0pt, ",y,"pt) circle (5pt)", sep=""))
@
\begin{tikzpicture}
\Sexpr{code}
\end{tikzpicture}

Which does not work ... I get the string instead of the drawing.

thomas
  • 43
  • 1
  • 6

1 Answers1

0

Don't use \Sexpr, just put the chunk in the tikzpicture environment, and add the chunk option results=tex. For example,

\begin{tikzpicture}
<<echo=FALSE, results=tex>>=
y <- 20
cat(paste0("\\draw (0pt, ",y,"pt) circle (5pt)", sep=""))
@
\end{tikzpicture}

This isn't tested, so you may need to tweak it a little.

user2554330
  • 37,248
  • 4
  • 43
  • 90