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

Thibaut Jombart jombart at biomserv.univ-lyon1.fr
Tue Feb 26 13:56:24 CET 2008


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?

Best,

Thibaut.

-- 
######################################
Thibaut JOMBART
CNRS UMR 5558 - Laboratoire de Biométrie et Biologie Evolutive
Universite Lyon 1
43 bd du 11 novembre 1918
69622 Villeurbanne Cedex
Tél. : 04.72.43.29.35
Fax : 04.72.43.13.88
jombart at biomserv.univ-lyon1.fr
http://lbbe.univ-lyon1.fr/-Jombart-Thibaut-.html?lang=en
http://adegenet.r-forge.r-project.org/



More information about the R-help mailing list