[Tikzdevice-bugs] Single file with tikzDevice

Gabor Grothendieck ggrothendieck at gmail.com
Sun Dec 6 22:29:25 CET 2009


Just thought I would add that there seemed to be a lot of interest in the
connection feature on that r-devel thread and since no other device can
output to an R variable (other than by writing out a file and reading it
back in) it might be that some users would use tikzDevice for this feature
alone regardless of whether it was implemented in terms of connections or
otherwise.

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

> Yes, I think that is the implication.  The basic desire is to be able to
> store the output in a variable (which might possibly be manipulated) and
> then print it out or embed it in a file later.
>
>
> On Sun, Dec 6, 2009 at 3:47 PM, Cameron Bracken <cameron.bracken at gmail.com
> > wrote:
>
>> Now if you call tikz with an empty file name
>>
>> tikz('')
>>
>> it will dump to the console. It cant be called with no file name
>> because that will default to the standard Rplots.tex file. The changes
>> are on Github.
>>
>> As for the rawConnection functionality, I do not know much about this
>> sort of R programming but I suppose it would be possible. Am I right
>> in thinking that afterward you might then
>>
>> print(rc)
>>
>> to output to a file?  It would certainly not be trivial on the C level
>> but I believe it could be done.
>>
>> -Cameron
>>
>>
>>
>> On Sun, Dec 6, 2009 at 1:28 PM, Gabor Grothendieck
>> <ggrothendieck at gmail.com> wrote:
>> > 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/406cb2ca/attachment-0001.htm 


More information about the Tikzdevice-bugs mailing list