Quantcast

Sweave support added to rgl package

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Sweave support added to rgl package

Duncan Murdoch-2
I have just committed some code to the rgl package on
https://r-forge.r-project.org/projects/rgl/ to allow rgl images to be
inserted into Sweave documents.  (This is not in the CRAN version yet.)  
It makes use of the custom graphics driver support added by Brian Ripley.

In R-devel (which will become R 2.14.0 next spring in New Zealand, next
fall in most other places), usage is quite straightforward.  For
example, code like this in a Sweave document:

<<fig=true, grdevice=rgl.Sweave, pdf=false, stayopen=TRUE>>=
x <- rnorm(100); y <- rnorm(100); z <- rnorm(100)
plot3d(x, y, z)
@

will insert a .png snapshot of the figure.  Because that chunk has
"stayopen=TRUE", it can be followed by another chunk to add
to the figure, e.g.

<<fig=true, grdevice=rgl.Sweave, pdf=false>>=
lines3d(x[1:10], y[1:10], z[1:10], col="red")
@

All of this is possible in R 2.13.0, but it takes more work:  see the
?rgl.Sweave help page.

I will eventually add postscript and PDF output options as well, and
perhaps some support for the LaTeX movie15 package, but those are not
there yet.  Comments or bug reports are welcome.

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Sweave support added to rgl package

Sharpie
Duncan Murdoch-2 wrote
I have just committed some code to the rgl package on
https://r-forge.r-project.org/projects/rgl/ to allow rgl images to be
inserted into Sweave documents.  (This is not in the CRAN version yet.)  
It makes use of the custom graphics driver support added by Brian Ripley.

In R-devel (which will become R 2.14.0 next spring in New Zealand, next
fall in most other places), usage is quite straightforward.  For
example, code like this in a Sweave document:

<<fig=true, grdevice=rgl.Sweave, pdf=false, stayopen=TRUE>>=
x <- rnorm(100); y <- rnorm(100); z <- rnorm(100)
plot3d(x, y, z)
@

will insert a .png snapshot of the figure.  Because that chunk has
"stayopen=TRUE", it can be followed by another chunk to add
to the figure, e.g.

<<fig=true, grdevice=rgl.Sweave, pdf=false>>=
lines3d(x[1:10], y[1:10], z[1:10], col="red")
@

All of this is possible in R 2.13.0, but it takes more work:  see the
?rgl.Sweave help page.

I will eventually add postscript and PDF output options as well, and
perhaps some support for the LaTeX movie15 package, but those are not
there yet.  Comments or bug reports are welcome.

Duncan Murdoch
This is great news Duncan!

If you do consider adding support for movie15, the Asymptote graphics language may be handy:

http://asymptote.sourceforge.net/

Asymptote can embed 3D graphs into LaTeX documents that are fully zoomable/manipulatable. It also uses LaTeX to typeset the figure text.

-Charlie
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Sweave support added to rgl package

Dominick Samperi-3
In reply to this post by Duncan Murdoch-2
On Tue, Apr 19, 2011 at 2:18 PM, Duncan Murdoch
<[hidden email]> wrote:

> I have just committed some code to the rgl package on
> https://r-forge.r-project.org/projects/rgl/ to allow rgl images to be
> inserted into Sweave documents.  (This is not in the CRAN version yet.)  It
> makes use of the custom graphics driver support added by Brian Ripley.
>
> In R-devel (which will become R 2.14.0 next spring in New Zealand, next fall
> in most other places), usage is quite straightforward.  For
> example, code like this in a Sweave document:
>
> <<fig=true, grdevice=rgl.Sweave, pdf=false, stayopen=TRUE>>=
> x <- rnorm(100); y <- rnorm(100); z <- rnorm(100)
> plot3d(x, y, z)
> @
>
> will insert a .png snapshot of the figure.  Because that chunk has
> "stayopen=TRUE", it can be followed by another chunk to add
> to the figure, e.g.
>
> <<fig=true, grdevice=rgl.Sweave, pdf=false>>=
> lines3d(x[1:10], y[1:10], z[1:10], col="red")
> @
>
> All of this is possible in R 2.13.0, but it takes more work:  see the
> ?rgl.Sweave help page.
>
> I will eventually add postscript and PDF output options as well, and perhaps
> some support for the LaTeX movie15 package, but those are not there yet.
>  Comments or bug reports are welcome.
>
> Duncan Murdoch

I inserted your example into testrgl.Rnw under R 2.13.0, with Sweave.snapshot()
at the end of both chunks, but things did not work as expected.

I used:
$ R CMD Sweave testrgl.Rnw
$ pdflatex tesetrgl
(view testrgl.pdf)

When R CMD Sweave is run the graphics is displayed interactively.

There is no graphics in the PDF file, even though both .png files
are read when pdflatex is run.

Thanks,
Dominick

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Sweave support added to rgl package

Duncan Murdoch-2
On 20/04/2011 1:52 PM, Dominick Samperi wrote:

> On Tue, Apr 19, 2011 at 2:18 PM, Duncan Murdoch
> <[hidden email]>  wrote:
> >  I have just committed some code to the rgl package on
> >  https://r-forge.r-project.org/projects/rgl/ to allow rgl images to be
> >  inserted into Sweave documents.  (This is not in the CRAN version yet.)  It
> >  makes use of the custom graphics driver support added by Brian Ripley.
> >
> >  In R-devel (which will become R 2.14.0 next spring in New Zealand, next fall
> >  in most other places), usage is quite straightforward.  For
> >  example, code like this in a Sweave document:
> >
> >  <<fig=true, grdevice=rgl.Sweave, pdf=false, stayopen=TRUE>>=
> >  x<- rnorm(100); y<- rnorm(100); z<- rnorm(100)
> >  plot3d(x, y, z)
> >  @
> >
> >  will insert a .png snapshot of the figure.  Because that chunk has
> >  "stayopen=TRUE", it can be followed by another chunk to add
> >  to the figure, e.g.
> >
> >  <<fig=true, grdevice=rgl.Sweave, pdf=false>>=
> >  lines3d(x[1:10], y[1:10], z[1:10], col="red")
> >  @
> >
> >  All of this is possible in R 2.13.0, but it takes more work:  see the
> >  ?rgl.Sweave help page.
> >
> >  I will eventually add postscript and PDF output options as well, and perhaps
> >  some support for the LaTeX movie15 package, but those are not there yet.
> >    Comments or bug reports are welcome.
> >
> >  Duncan Murdoch
>
> I inserted your example into testrgl.Rnw under R 2.13.0, with Sweave.snapshot()
> at the end of both chunks, but things did not work as expected.
>
> I used:
> $ R CMD Sweave testrgl.Rnw
> $ pdflatex tesetrgl
> (view testrgl.pdf)
>
> When R CMD Sweave is run the graphics is displayed interactively.

That's unavoidable as far as I know.  I don't think there's a general
purpose way to tell OpenGL to render in the background, so it works by
rendering on screen, then copying a bitmap to the .png file.
> There is no graphics in the PDF file, even though both .png files
> are read when pdflatex is run.

Do they look okay?  One possible problem is that you may have asked for
a bitmap too big for your hardware to render, in which case those png
files will end up with junk (probably blank).  Setting resolution=100 in
the chunk headers will do it more coarsely.  (The default is 300 dpi.)  
The same effect comes from width=1, height=1  (or some other small numbers).

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Sweave support added to rgl package

Duncan Murdoch-2
In reply to this post by Sharpie
On 20/04/2011 1:28 PM, Sharpie wrote:

> Duncan Murdoch-2 wrote:
> >
> >  I have just committed some code to the rgl package on
> >  https://r-forge.r-project.org/projects/rgl/ to allow rgl images to be
> >  inserted into Sweave documents.  (This is not in the CRAN version yet.)
> >  It makes use of the custom graphics driver support added by Brian Ripley.
> >
> >  In R-devel (which will become R 2.14.0 next spring in New Zealand, next
> >  fall in most other places), usage is quite straightforward.  For
> >  example, code like this in a Sweave document:
> >
> >  <&lt;fig=true, grdevice=rgl.Sweave, pdf=false, stayopen=TRUE&gt;>=
> >  x<- rnorm(100); y<- rnorm(100); z<- rnorm(100)
> >  plot3d(x, y, z)
> >  @
> >
> >  will insert a .png snapshot of the figure.  Because that chunk has
> >  "stayopen=TRUE", it can be followed by another chunk to add
> >  to the figure, e.g.
> >
> >  <&lt;fig=true, grdevice=rgl.Sweave, pdf=false&gt;>=
> >  lines3d(x[1:10], y[1:10], z[1:10], col="red")
> >  @
> >
> >  All of this is possible in R 2.13.0, but it takes more work:  see the
> >  ?rgl.Sweave help page.
> >
> >  I will eventually add postscript and PDF output options as well, and
> >  perhaps some support for the LaTeX movie15 package, but those are not
> >  there yet.  Comments or bug reports are welcome.
> >
> >  Duncan Murdoch
> >
>
> This is great news Duncan!
>
> If you do consider adding support for movie15, the Asymptote graphics
> language may be handy:
>
> http://asymptote.sourceforge.net/
>
> Asymptote can embed 3D graphs into LaTeX documents that are fully
> zoomable/manipulatable. It also uses LaTeX to typeset the figure text.

Thanks.  That doesn't look easy, but it would indeed be a nice addition.

Duncan Murdoch


> -Charlie
>
>
> -----
> Charlie Sharpsteen
> Undergraduate-- Environmental Resources Engineering
> Humboldt State University
> --
> View this message in context: http://r.789695.n4.nabble.com/Sweave-support-added-to-rgl-package-tp3461163p3463653.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Sweave support added to rgl package

Dominick Samperi-3
In reply to this post by Duncan Murdoch-2
On Wed, Apr 20, 2011 at 2:29 PM, Duncan Murdoch
<[hidden email]> wrote:

> On 20/04/2011 1:52 PM, Dominick Samperi wrote:
>>
>> On Tue, Apr 19, 2011 at 2:18 PM, Duncan Murdoch
>> <[hidden email]>  wrote:
>> >  I have just committed some code to the rgl package on
>> >  https://r-forge.r-project.org/projects/rgl/ to allow rgl images to be
>> >  inserted into Sweave documents.  (This is not in the CRAN version yet.)
>> >  It
>> >  makes use of the custom graphics driver support added by Brian Ripley.
>> >
>> >  In R-devel (which will become R 2.14.0 next spring in New Zealand, next
>> > fall
>> >  in most other places), usage is quite straightforward.  For
>> >  example, code like this in a Sweave document:
>> >
>> >  <<fig=true, grdevice=rgl.Sweave, pdf=false, stayopen=TRUE>>=
>> >  x<- rnorm(100); y<- rnorm(100); z<- rnorm(100)
>> >  plot3d(x, y, z)
>> >  @
>> >
>> >  will insert a .png snapshot of the figure.  Because that chunk has
>> >  "stayopen=TRUE", it can be followed by another chunk to add
>> >  to the figure, e.g.
>> >
>> >  <<fig=true, grdevice=rgl.Sweave, pdf=false>>=
>> >  lines3d(x[1:10], y[1:10], z[1:10], col="red")
>> >  @
>> >
>> >  All of this is possible in R 2.13.0, but it takes more work:  see the
>> >  ?rgl.Sweave help page.
>> >
>> >  I will eventually add postscript and PDF output options as well, and
>> > perhaps
>> >  some support for the LaTeX movie15 package, but those are not there
>> > yet.
>> >    Comments or bug reports are welcome.
>> >
>> >  Duncan Murdoch
>>
>> I inserted your example into testrgl.Rnw under R 2.13.0, with
>> Sweave.snapshot()
>> at the end of both chunks, but things did not work as expected.
>>
>> I used:
>> $ R CMD Sweave testrgl.Rnw
>> $ pdflatex tesetrgl
>> (view testrgl.pdf)
>>
>> When R CMD Sweave is run the graphics is displayed interactively.
>
> That's unavoidable as far as I know.  I don't think there's a general
> purpose way to tell OpenGL to render in the background, so it works by
> rendering on screen, then copying a bitmap to the .png file.
>>
>> There is no graphics in the PDF file, even though both .png files
>> are read when pdflatex is run.
>
> Do they look okay?  One possible problem is that you may have asked for a
> bitmap too big for your hardware to render, in which case those png files
> will end up with junk (probably blank).  Setting resolution=100 in the chunk
> headers will do it more coarsely.  (The default is 300 dpi.)  The same
> effect comes from width=1, height=1  (or some other small numbers).
>
> Duncan Murdoch
>

The resolution=100 tip fixed the problem, thanks. Now I see the snapshots
in the PDF file. Using this in a package will certainly change the
user experience,
but it moves away from the traditional batch-oriented R package
processing, it seems to me.

The idea of adding support for movies and 3D graphics to Sweave/PDF files
sounds very interesting and revolutionary.

Dominick

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Sweave support added to rgl package

Duncan Murdoch-2
On 20/04/2011 7:10 PM, Dominick Samperi wrote:

> On Wed, Apr 20, 2011 at 2:29 PM, Duncan Murdoch
> <[hidden email]>  wrote:
>> On 20/04/2011 1:52 PM, Dominick Samperi wrote:
>>>
>>> On Tue, Apr 19, 2011 at 2:18 PM, Duncan Murdoch
>>> <[hidden email]>    wrote:
>>>>   I have just committed some code to the rgl package on
>>>>   https://r-forge.r-project.org/projects/rgl/ to allow rgl images to be
>>>>   inserted into Sweave documents.  (This is not in the CRAN version yet.)
>>>>   It
>>>>   makes use of the custom graphics driver support added by Brian Ripley.
>>>>
>>>>   In R-devel (which will become R 2.14.0 next spring in New Zealand, next
>>>> fall
>>>>   in most other places), usage is quite straightforward.  For
>>>>   example, code like this in a Sweave document:
>>>>
>>>>   <<fig=true, grdevice=rgl.Sweave, pdf=false, stayopen=TRUE>>=
>>>>   x<- rnorm(100); y<- rnorm(100); z<- rnorm(100)
>>>>   plot3d(x, y, z)
>>>>   @
>>>>
>>>>   will insert a .png snapshot of the figure.  Because that chunk has
>>>>   "stayopen=TRUE", it can be followed by another chunk to add
>>>>   to the figure, e.g.
>>>>
>>>>   <<fig=true, grdevice=rgl.Sweave, pdf=false>>=
>>>>   lines3d(x[1:10], y[1:10], z[1:10], col="red")
>>>>   @
>>>>
>>>>   All of this is possible in R 2.13.0, but it takes more work:  see the
>>>>   ?rgl.Sweave help page.
>>>>
>>>>   I will eventually add postscript and PDF output options as well, and
>>>> perhaps
>>>>   some support for the LaTeX movie15 package, but those are not there
>>>> yet.
>>>>     Comments or bug reports are welcome.
>>>>
>>>>   Duncan Murdoch
>>>
>>> I inserted your example into testrgl.Rnw under R 2.13.0, with
>>> Sweave.snapshot()
>>> at the end of both chunks, but things did not work as expected.
>>>
>>> I used:
>>> $ R CMD Sweave testrgl.Rnw
>>> $ pdflatex tesetrgl
>>> (view testrgl.pdf)
>>>
>>> When R CMD Sweave is run the graphics is displayed interactively.
>>
>> That's unavoidable as far as I know.  I don't think there's a general
>> purpose way to tell OpenGL to render in the background, so it works by
>> rendering on screen, then copying a bitmap to the .png file.
>>>
>>> There is no graphics in the PDF file, even though both .png files
>>> are read when pdflatex is run.
>>
>> Do they look okay?  One possible problem is that you may have asked for a
>> bitmap too big for your hardware to render, in which case those png files
>> will end up with junk (probably blank).  Setting resolution=100 in the chunk
>> headers will do it more coarsely.  (The default is 300 dpi.)  The same
>> effect comes from width=1, height=1  (or some other small numbers).
>>
>> Duncan Murdoch
>>
>
> The resolution=100 tip fixed the problem, thanks.

I'll see if I am skipping over some error message in there.  It would be
much better for Sweave to fail with an error than generate empty images.


 > Now I see the snapshots
> in the PDF file. Using this in a package will certainly change the
> user experience,
> but it moves away from the traditional batch-oriented R package
> processing, it seems to me.

I don't follow that.

> The idea of adding support for movies and 3D graphics to Sweave/PDF files
> sounds very interesting and revolutionary.

Movies will likely be pretty slow.  I think you'll want caching of some
sort if you want to produce those.

Duncan Murdoch

>
> Dominick

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Sweave support added to rgl package

Duncan Murdoch-2
I've just committed some changes to rgl that will probably detect
bitmaps that are specified to be too large.  As well, Brian Ripley
backported some of the R-devel additions to the RweaveLatex driver, so
now R 2.13.0-patched (revision 55572 or newer) should
work as well as R-devel.

Duncan Murdoch

On 20/04/2011 8:56 PM, Duncan Murdoch wrote:

> On 20/04/2011 7:10 PM, Dominick Samperi wrote:
> >  On Wed, Apr 20, 2011 at 2:29 PM, Duncan Murdoch
> >  <[hidden email]>   wrote:
> >>  On 20/04/2011 1:52 PM, Dominick Samperi wrote:
> >>>
> >>>  On Tue, Apr 19, 2011 at 2:18 PM, Duncan Murdoch
> >>>  <[hidden email]>     wrote:
> >>>>    I have just committed some code to the rgl package on
> >>>>    https://r-forge.r-project.org/projects/rgl/ to allow rgl images to be
> >>>>    inserted into Sweave documents.  (This is not in the CRAN version yet.)
> >>>>    It
> >>>>    makes use of the custom graphics driver support added by Brian Ripley.
> >>>>
> >>>>    In R-devel (which will become R 2.14.0 next spring in New Zealand, next
> >>>>  fall
> >>>>    in most other places), usage is quite straightforward.  For
> >>>>    example, code like this in a Sweave document:
> >>>>
> >>>>    <<fig=true, grdevice=rgl.Sweave, pdf=false, stayopen=TRUE>>=
> >>>>    x<- rnorm(100); y<- rnorm(100); z<- rnorm(100)
> >>>>    plot3d(x, y, z)
> >>>>    @
> >>>>
> >>>>    will insert a .png snapshot of the figure.  Because that chunk has
> >>>>    "stayopen=TRUE", it can be followed by another chunk to add
> >>>>    to the figure, e.g.
> >>>>
> >>>>    <<fig=true, grdevice=rgl.Sweave, pdf=false>>=
> >>>>    lines3d(x[1:10], y[1:10], z[1:10], col="red")
> >>>>    @
> >>>>
> >>>>    All of this is possible in R 2.13.0, but it takes more work:  see the
> >>>>    ?rgl.Sweave help page.
> >>>>
> >>>>    I will eventually add postscript and PDF output options as well, and
> >>>>  perhaps
> >>>>    some support for the LaTeX movie15 package, but those are not there
> >>>>  yet.
> >>>>      Comments or bug reports are welcome.
> >>>>
> >>>>    Duncan Murdoch
> >>>
> >>>  I inserted your example into testrgl.Rnw under R 2.13.0, with
> >>>  Sweave.snapshot()
> >>>  at the end of both chunks, but things did not work as expected.
> >>>
> >>>  I used:
> >>>  $ R CMD Sweave testrgl.Rnw
> >>>  $ pdflatex tesetrgl
> >>>  (view testrgl.pdf)
> >>>
> >>>  When R CMD Sweave is run the graphics is displayed interactively.
> >>
> >>  That's unavoidable as far as I know.  I don't think there's a general
> >>  purpose way to tell OpenGL to render in the background, so it works by
> >>  rendering on screen, then copying a bitmap to the .png file.
> >>>
> >>>  There is no graphics in the PDF file, even though both .png files
> >>>  are read when pdflatex is run.
> >>
> >>  Do they look okay?  One possible problem is that you may have asked for a
> >>  bitmap too big for your hardware to render, in which case those png files
> >>  will end up with junk (probably blank).  Setting resolution=100 in the chunk
> >>  headers will do it more coarsely.  (The default is 300 dpi.)  The same
> >>  effect comes from width=1, height=1  (or some other small numbers).
> >>
> >>  Duncan Murdoch
> >>
> >
> >  The resolution=100 tip fixed the problem, thanks.
>
> I'll see if I am skipping over some error message in there.  It would be
> much better for Sweave to fail with an error than generate empty images.
>
>
>   >  Now I see the snapshots
> >  in the PDF file. Using this in a package will certainly change the
> >  user experience,
> >  but it moves away from the traditional batch-oriented R package
> >  processing, it seems to me.
>
> I don't follow that.
>
> >  The idea of adding support for movies and 3D graphics to Sweave/PDF files
> >  sounds very interesting and revolutionary.
>
> Movies will likely be pretty slow.  I think you'll want caching of some
> sort if you want to produce those.
>
> Duncan Murdoch
>
> >
> >  Dominick
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Loading...