And yet another comment. There has been a recent discussion about allowing devices to output to connections on r-devel and apparently this has languished for years despite Jeffrey Horner posting code which would have allowed it 3 years ago. Would it be a problem for tikz to handle that even if the other devices don't? For example, Hadley Wickham had posted this proposed functionality:<br>
<br>rc <- <span class="il">rawConnection</span>("raw.img", "w")<br>
png(rc)<br>
<div class="im">plot(1:10)<br>
dev.off()<br>
</div>close(rc)<br>
<br>where in this case png() would be replaced with tikz().<br><br><div class="gmail_quote">
On Sun, Dec 6, 2009 at 3:17 PM, Gabor Grothendieck <span dir="ltr"><<a href="mailto:ggrothendieck@gmail.com" target="_blank">ggrothendieck@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Great. Just one other related comment. I think I would likely use the tikz(..., append=TRUE) style but some might prefer to use sink. That could be done if it were possible to write the output to stdout like this. If its not a problem you might want to add that too.<br>
<br>sink("myfile.tex")<div><br>cat("\\documentclass{article}<br>\\usepackage{tikz}<br>\begin{document}<br>\\begin{figure}[ht]<br>\\centering<br></div>")<br># "" or "stdout" or default writes to stdout<br>
tikz(width=5, height=5)<div><br>x <- rnorm(100)<br>plot(x)<br></div><div>dev.off()<br>cat("\\caption{caption}<br>\\label{fig:inline}<br>\\end{figure}<br>\\end{document}<br></div>")<br>sink()<div>
<div></div><div><br><br><br><br><div class="gmail_quote">
On Sun, Dec 6, 2009 at 3:04 PM, Cameron Bracken <span dir="ltr"><<a href="mailto:cameron.bracken@gmail.com" target="_blank">cameron.bracken@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I liked this idea so much that I implemented it right away. You can<br>
get it from the master branch of my github fork until the next release<br>
<br>
<a href="http://github.com/cameronbracken/rtikzdevice/network" target="_blank">http://github.com/cameronbracken/rtikzdevice/network</a><br>
<br>
Instead of "append" i called it "console." It works nearly as you envisioned:<br>
<div><br>
cat("\\documentclass{article}<br>
\\usepackage{tikz}<br>
<br>
\\begin{document}<br>
\\begin{figure}[ht]<br>
\\centering<br>
", file = "myfile.tex")<br>
<br>
</div>sink("myfile.tex",append=T)<br>
tikz(console=T, width=5, height=5)<br>
<div><br>
x <- rnorm(100)<br>
plot(x)<br>
</div>quiet <- dev.off()<br>
sink()<br>
<div><br>
cat("\\caption{caption}<br>
<br>
\\label{fig:inline}<br>
\\end{figure}<br>
\\end{document}<br>
", file = "myfile.tex", append = TRUE)<br>
<br>
</div>The following will now produce a self contained tex file:<br>
<div><br>
\documentclass{article}<br>
\usepackage{tikz}<br>
\usepackage[nogin]{Sweave}<br>
\begin{document}<br>
\begin{figure}[ht]<br>
\centering<br>
<<inline,echo=F,results=tex>>=<br>
<br>
require(tikzDevice)<br>
</div> tikz(console=T,width=5,height=5)<br>
<div> x <- rnorm(100)<br>
plot(x)<br>
</div> dummy <- dev.off()<br>
<div><br>
@<br>
\caption{caption}<br>
\label{fig:inline}<br>
\end{figure}<br>
\end{document}<br>
<br>
<br>
-Cameron<br>
<br>
<br>
</div>On Sun, Dec 6, 2009 at 9:46 AM, Gabor Grothendieck<br>
<div><div></div><div><<a href="mailto:ggrothendieck@gmail.com" target="_blank">ggrothendieck@gmail.com</a>> wrote:<br>
> If you able to provide this feature (i.e. incorporate the tikz tex directly<br>
> into the current file rather than writing out a temporary file and reading<br>
> it back in) then that would be useful since one of the key potential<br>
> advantages of tikz and pgf are the ability to have a single file rather than<br>
> multiple files. Perhaps an append=TRUE argument like this:<br>
><br>
> cat("\\documentclass{article}<br>
> \\usepackage{tikz}<br>
> \begin{document}<br>
> \\begin{figure}[ht]<br>
> \\centering<br>
> ", file = "myfile.tex")<br>
> tikz("myfile.tex", width=5, height=5, append = TRUE)<br>
> x <- rnorm(100)<br>
> plot(x)<br>
> dev.off()<br>
> cat("\\caption{caption}<br>
> \\label{fig:inline}<br>
> \\end{figure}<br>
> \\end{document}<br>
> ", file = "myfile.tex", append = TRUE)<br>
><br>
> On Sun, Dec 6, 2009 at 11:34 AM, Cameron Bracken <<a href="mailto:cameron.bracken@gmail.com" target="_blank">cameron.bracken@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Interesting Idea. This should work with plain Sweave. It is not very<br>
>> efficient and would be very slow for large files since it must write<br>
>> out then read in then write out.<br>
>><br>
>> \documentclass{article}<br>
>> \usepackage{tikz}<br>
>> \usepackage[nogin]{Sweave}<br>
>> \begin{document}<br>
>> \begin{figure}[ht]<br>
>> \centering<br>
>> <<inline,echo=F,results=tex>>=<br>
>><br>
>> require(tikzDevice)<br>
>> tf <- tempfile()<br>
>> tikz(tf,width=5,height=5)<br>
>> x <- rnorm(100)<br>
>> plot(x)<br>
>> #Suppress "null device 1" from being printed<br>
>> dummy <- dev.off()<br>
>> cat(readLines(tf),sep='\n')<br>
>><br>
>> @<br>
>> \caption{caption}<br>
>> \label{fig:inline}<br>
>> \end{figure}<br>
>> \end{document}<br>
>><br>
>><br>
>> -Cameron<br>
>><br>
>><br>
>><br>
>> On Sun, Dec 6, 2009 at 9:02 AM, Gabor Grothendieck<br>
>> <<a href="mailto:ggrothendieck@gmail.com" target="_blank">ggrothendieck@gmail.com</a>> wrote:<br>
>> > I would like to create a single file that has my latex and tikzDevice<br>
>> > output<br>
>> > as opposed to outputting the tikZ output into a separate file and using<br>
>> > \input . The latex would be generated using cat statements in R.<br>
>> ><br>
>> > Can that be done? If so, can you provide a small example.<br>
>> ><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>