[R] How to include the documentation of a function in a Sweave document?
Jean lobry
lobry at biomserv.univ-lyon1.fr
Tue Feb 26 21:59:14 CET 2008
Dear all,
thanks for your suggestions. I like the idea of including directly
the LaTeX file corresponding to the targeted topic, however, my
understanding from the reading of ?help is that these LaTeX files
are not always available, depending on the build of R.
I found a solution that works well enough for me by removing
the backslashes from the help file this way:
-------- tmp.rnw --------
\documentclass{article}
\begin{document}
<<mypager,echo=F,eval=T>>=
mypager <- function(..., header = rep("", nfiles),
title = "R Information", delete.file = FALSE){
args <- list(...)
sanitize <- function(strings){
f <- function(x){
x.raw <- charToRaw(x)
backspaces <- which(x.raw == charToRaw('\b'))
if(length(backspaces) > 0){
x.raw <- x.raw[-c(backspaces, backspaces - 1)] # remove "_\b"
}
rawToChar(x.raw[x.raw >= as.raw(20)]) # remove non-printable ASCII
}
res <- sapply(strings, f)
names(res) <- NULL
return(res)
}
help.out <- lapply(args[[1]], readLines)
help.out <- lapply(help.out, sanitize)
lapply(help.out, cat, sep = "\n")
}
@
<<echo=T,print=F,eval=F, keep.source=T>>=
?plot
@
<<echo=F,print=T,eval=T>>=
help("plot", chmhelp = FALSE, htmlhelp = FALSE, pager = mypager)
@
\end{document}
-------- tmp.rnw --------
This works well for me when I'm Sweaving the file from an R
session in the CLI interface in a terminal, but not when I'm
Sweaving the file from the R GUI for the Mac (the function
mypager is not called despite pager = mypager when calling
the help function, don't understand why).
The PDF looks like this:
http://pbil.univ-lyon1.fr/members/lobry/tmp/tmp.pdf
Thanks again for your help,
Best,
Jean
--
Jean R. Lobry (lobry at biomserv.univ-lyon1.fr)
Laboratoire BBE-CNRS-UMR-5558, Univ. C. Bernard - LYON I,
43 Bd 11/11/1918, F-69622 VILLEURBANNE CEDEX, FRANCE
allo : +33 472 43 27 56 fax : +33 472 43 13 88
http://pbil.univ-lyon1.fr/members/lobry/
More information about the R-help
mailing list