[Tikzdevice-bugs] Single file with tikzDevice

Gabor Grothendieck ggrothendieck at gmail.com
Sun Dec 6 21:28:32 CET 2009


img.raw is intended to represent the name of a raw R object, not a file
name.

On Sun, Dec 6, 2009 at 3:25 PM, Gabor Grothendieck
<ggrothendieck at gmail.com>wrote:

> 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:
>
> rc <- rawConnection("raw.img", "w")
> png(rc)
> plot(1:10)
> dev.off()
> close(rc)
>
> where in this case png() would be replaced with tikz().
>
>
> On Sun, Dec 6, 2009 at 3:17 PM, Gabor Grothendieck <
> ggrothendieck at gmail.com> wrote:
>
>> 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.
>>
>> sink("myfile.tex")
>>
>> cat("\\documentclass{article}
>> \\usepackage{tikz}
>> \begin{document}
>> \\begin{figure}[ht]
>> \\centering
>> ")
>> # "" or "stdout" or default writes to stdout
>> tikz(width=5, height=5)
>>
>> x <- rnorm(100)
>> plot(x)
>> dev.off()
>> cat("\\caption{caption}
>> \\label{fig:inline}
>> \\end{figure}
>> \\end{document}
>> ")
>> sink()
>>
>>
>>
>>
>> On Sun, Dec 6, 2009 at 3:04 PM, Cameron Bracken <
>> cameron.bracken at gmail.com> wrote:
>>
>>> I liked this idea so much that I implemented it right away. You can
>>> get it from the master branch of my github fork until the next release
>>>
>>> http://github.com/cameronbracken/rtikzdevice/network
>>>
>>> Instead of "append" i called it "console."  It works nearly as you
>>> envisioned:
>>>
>>> cat("\\documentclass{article}
>>> \\usepackage{tikz}
>>>
>>> \\begin{document}
>>> \\begin{figure}[ht]
>>> \\centering
>>> ", file = "myfile.tex")
>>>
>>> sink("myfile.tex",append=T)
>>> tikz(console=T, width=5, height=5)
>>>
>>> x <- rnorm(100)
>>> plot(x)
>>> quiet <- dev.off()
>>> sink()
>>>
>>> cat("\\caption{caption}
>>>
>>> \\label{fig:inline}
>>> \\end{figure}
>>> \\end{document}
>>> ", file = "myfile.tex", append = TRUE)
>>>
>>> The following will now produce a self contained tex file:
>>>
>>> \documentclass{article}
>>> \usepackage{tikz}
>>> \usepackage[nogin]{Sweave}
>>> \begin{document}
>>> \begin{figure}[ht]
>>> \centering
>>> <<inline,echo=F,results=tex>>=
>>>
>>>  require(tikzDevice)
>>>   tikz(console=T,width=5,height=5)
>>>     x <- rnorm(100)
>>>    plot(x)
>>>   dummy <- dev.off()
>>>
>>> @
>>> \caption{caption}
>>> \label{fig:inline}
>>> \end{figure}
>>> \end{document}
>>>
>>>
>>> -Cameron
>>>
>>>
>>> On Sun, Dec 6, 2009 at 9:46 AM, Gabor Grothendieck
>>> <ggrothendieck at gmail.com> wrote:
>>> > If you able to provide this feature (i.e. incorporate the tikz tex
>>> directly
>>> > into the current file rather than writing out a temporary file and
>>> reading
>>> > it back in) then that would be useful since one of the key potential
>>> > advantages of tikz and pgf are the ability to have a single file rather
>>> than
>>> > multiple files.  Perhaps an append=TRUE argument like this:
>>> >
>>> > cat("\\documentclass{article}
>>> > \\usepackage{tikz}
>>> > \begin{document}
>>> > \\begin{figure}[ht]
>>> > \\centering
>>> > ", file = "myfile.tex")
>>> > tikz("myfile.tex", width=5, height=5, append = TRUE)
>>> > x <- rnorm(100)
>>> > plot(x)
>>> > dev.off()
>>> > cat("\\caption{caption}
>>> > \\label{fig:inline}
>>> > \\end{figure}
>>> > \\end{document}
>>> > ", file = "myfile.tex", append = TRUE)
>>> >
>>> > On Sun, Dec 6, 2009 at 11:34 AM, Cameron Bracken <
>>> cameron.bracken at gmail.com>
>>> > wrote:
>>> >>
>>> >> Interesting Idea.  This should work with plain Sweave.  It is not very
>>> >> efficient and would be very slow for large files since it must write
>>> >> out then read in then write out.
>>> >>
>>> >> \documentclass{article}
>>> >> \usepackage{tikz}
>>> >> \usepackage[nogin]{Sweave}
>>> >> \begin{document}
>>> >> \begin{figure}[ht]
>>> >> \centering
>>> >> <<inline,echo=F,results=tex>>=
>>> >>
>>> >>  require(tikzDevice)
>>> >>  tf <- tempfile()
>>> >>  tikz(tf,width=5,height=5)
>>> >>    x <- rnorm(100)
>>> >>    plot(x)
>>> >>  #Suppress "null device 1" from being printed
>>> >>  dummy <- dev.off()
>>> >>  cat(readLines(tf),sep='\n')
>>> >>
>>> >> @
>>> >> \caption{caption}
>>> >> \label{fig:inline}
>>> >> \end{figure}
>>> >> \end{document}
>>> >>
>>> >>
>>> >> -Cameron
>>> >>
>>> >>
>>> >>
>>> >> On Sun, Dec 6, 2009 at 9:02 AM, Gabor Grothendieck
>>> >> <ggrothendieck at gmail.com> wrote:
>>> >> > I would like to create a single file that has my latex and
>>> tikzDevice
>>> >> > output
>>> >> > as opposed to outputting the tikZ output into a separate file and
>>> using
>>> >> > \input .  The latex would be generated using cat statements in R.
>>> >> >
>>> >> > Can that be done?  If so, can you provide a small example.
>>> >> >
>>> >> >
>>> >
>>> >
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.r-forge.r-project.org/pipermail/tikzdevice-bugs/attachments/20091206/dc6d8200/attachment.htm 


More information about the Tikzdevice-bugs mailing list