Search code examples
rlatexsweave

Getting the list of functions in an R package to be used in LaTex


I used

library(help="stats")$"info"[[2]]

to get the list of available functions with their description in stats. I'd like to make a table out of this using xtable to be use in Sweave for LaTex.

I used this command in R:

library(xtable)
xtable(library(help="stats")$"info"[[2]])

and got the following error message:

Error in UseMethod("xtable") : 
  no applicable method for 'xtable' applied to an object of class "character"

I'd highly appreciate if someone guide me to do this. Thanks in advance.


Solution

  • Here is how I did the task the Patrick advises (before I saw his answer):

    library(xtable)
    library(Hmisc) # for latex()
    tst<-library(help="stats")$"info"[[2]]
    tdf <- data.frame(namefn = unlist(lapply(
                                 strsplit(sub("\\s+", "\t", tst), "\t"), 
                                 "[", 1)),
                      descrb = unlist(lapply(
                                 strsplit(sub("\\s+", "\t", tst), "\t"), 
                                 "[", 2)) )
    xdf <- xtable(tdf)
    latex(xdf, longtable=TRUE)
    

    You will probably want to renames the dataframe's columns but this does get you the multi-page latex output needed to accommodate that 300+ line output that you specified.