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

From: Jean lobry <lobry_at_biomserv.univ-lyon1.fr>
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,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/

______________________________________________
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 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive