[R] including figures in html documentation/help

Jannis bt_jannis at yahoo.de
Wed Jul 6 16:37:21 CEST 2011


Dear Duncan,

OK, my fault. I did not realize that you only refer to r-devel. I found however a way for standard R by putting this into the Rd file:


\details{
\if{html}{\out{<img src="../doc/image_name.png" alt="image .. should be
here"/>}}\ifelse{latex}{}{} 
}

And saving the figure in inst/doc.

Now I just need to find a way to get Inlinedocs to pass this code from the sourcecode of the function directly into the Rd files but I am sure some googeling will help me :-).

Thanks again for the help!
Jannis

--- Duncan Murdoch <murdoch.duncan at gmail.com> schrieb am Mi, 6.7.2011:

> Von: Duncan Murdoch <murdoch.duncan at gmail.com>
> Betreff: Re: [R] including figures in html documentation/help
> An: "Jannis" <bt_jannis at yahoo.de>
> CC: r-help at r-project.org
> Datum: Mittwoch, 6. Juli, 2011 14:11 Uhr
> On 06/07/2011 10:03 AM, Jannis
> wrote:
> > Thanks for your advice Duncan. In which file should I
> put the
> > 
> > \figure{}
> > 
> > command? I tried the *.Rd file, but the html files
> created are without the figure. Are you sure I only need to
> include the filename and no path?
> 
> Yes, in the .Rd file.
> 
> Can't really diagnose what went wrong for you, but my first
> guess would be that you're not using a sufficiently recent
> R-devel.
> 
> Duncan Murdoch
> 
> > 
> > Jannis
> > 
> > --- Duncan Murdoch<murdoch.duncan at gmail.com> schrieb am Mi, 6.7.2011:
> > 
> > >  Von: Duncan Murdoch<murdoch.duncan at gmail.com>
> > >  Betreff: Re: [R] including figures in html
> documentation/help
> > >  An: "Jannis"<bt_jannis at yahoo.de>
> > >  CC: r-help at r-project.org
> > >  Datum: Mittwoch, 6. Juli, 2011 13:04 Uhr
> > >  On 11-07-06 8:47 AM, Jannis wrote:
> > >  >  Dear list members,
> > >  >
> > >  >  is it somehow possible to
> include figures to the html
> > >  help pages of individueal functions
> (containing for example
> > >  a plot produced by that function?)
> > >  >
> > >  >  I thought about adding these
> figures into a 'graphs'
> > >  subfolder of the package folder and then to
> somehow insert
> > >  some sort of html link into the
> documentation code.
> > >  >
> > >  >  I use inlinedocs for creating
> the documentation.
> > >
> > >  Not in the current release, but this
> feature has been added
> > >  to R-devel (which will be released at the
> end of October).
> > >
> > >  The simplest form is to put
> > >
> > >  \figure{filename.png}
> > >
> > >  into your help page.  The
> "filename.png" file should
> > >  be stored in the man/figures directory of
> your package.
> > >
> > >  You can also generate figures using R code,
> but it's a
> > >  little tricky to make sure the generated
> files are stored in
> > >  the right place.  Here's an ugly
> example, which will
> > >  probably be simpler by release time:
> > >
> > >  \Sexpr[stage=render,results=rd]{
> > >        library(testpkg) 
> # This is
> > >  the package with the example
> > >        library(grDevices)
> > >        filename<-
> > >  tempfile(fileext=".png")
> > >        png(file=filename)
> > >        plot(rnorm(100))
> > >        dev.off()
> > >  >     
> paste("\\\\ifelse{html}{\\\\figure{",
> > >  file.path("../../../session",
> basename(filename)),
> > >  >      "}}{\\\\figure{",
> normalizePath(filename,
> > >  "/"), "}}", sep="")
> > >  }
> > >
> > >
> > >  Documentation on this is currently sparse,
> but it's there.
> > >
> > >  Duncan Murdoch
> > >
> 
>



More information about the R-help mailing list