Re: [R] How to include the documentation of a function in a Sweave document?

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Tue, 26 Feb 2008 20:18:57 -0500

Thibaut Jombart wrote:

> Duncan Murdoch wrote:
>   

>>>>
>>>>
>>> Maybe a clue: we can use
>>> cat(readLines(as.character(?plot)),sep="\n")
>>>
>>> to display the help (here, of plot) directly to the screen. So we could
>>> use something like:
>>>
>>> <<echo=TRUE,print=FALSE,eval=FALSE>>=
>>> ?plot
>>> @
>>>
>>>
>>> <<echo=FALSE,print=TRUE,eval=TRUE>>=
>>> cat(readLines(as.character(?plot)),sep="\n")
>>> @
>>>
>>> But this doesn't work (latex compilation error) as weird characters
>>> appear in the produced tex, at some places (tabulations?), like:
>>>
>>> _T_h_e _D_e_f_a_
>>>
>>> (not sure what it will look like in this email, but emacs reads things
>>> like _^HT_^HH_^He...).
>>>
>>> Maybe an encoding problem? I tried specifying different encoding to
>>> readLines, with no luck (latin1, UTF-8). Otherwise, the help appears
>>> in the .tex.
>>>
>> Those are backspaces:  it's trying to underline the title.  You'd get 
>> a better display if you read the latex version instead.  I think you 
>> need to construct the path to it yourself (using system.file() etc.)
>>
>> Duncan Murdoch
>>
>>
>>
>>     
> Thanks for the hint !
> So, the code below roughly works:
>
> #######
> \documentclass{article}
> \usepackage{verbatim}
> \begin{document}
> <<echo=TRUE,print=FALSE,eval=FALSE>>=
> ?plot
> @
>
>
> <<echo=FALSE,print=FALSE,results=tex>>=
> path <- sub("help","latex",as.character(?plot))
> path <- paste(path,'tex',sep=".")
> cat(readLines(path),sep="\n")
> @
>
> \end{document}
> #######
>
> The document compiles with pdflatex but still complains about a bunch of 
> unknown latex instructions (like \HeaderA, used at the begining of the 
> included (plot.tex) tex file. The resulting pdf indeed looks a bit nasty.
>
> What command shall we include in the header to have it work?
>   

The refman.tex file starts like this:

\documentclass[a4paper]{book}
\usepackage[times,hyper]{Rd}
\usepackage[latin1]{inputenc}
\usepackage{makeidx}

Those packages should do it. (Rd.sty is in R_HOME/share/texmf).

Duncan Murdoch



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 27 Feb 2008 - 01:26:02 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 27 Feb 2008 - 01:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive