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

From: Jean lobry <>
Date: Tue, 26 Feb 2008 21:59:14 +0100

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:

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

   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
help("plot", chmhelp = FALSE, htmlhelp = FALSE, pager = mypager) @


-------- 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:

Thanks again for your help,



Jean R. Lobry            (
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

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 26 Feb 2008 - 21:02:17 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 Tue 26 Feb 2008 - 21:30:17 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive