R函数以`.tex`或`.Rnw`格式提供帮助

MYa*_*208 4 latex r noamtools

我可以使用或获取格式的任何R函数的帮助.我想知道我是否可以在dociument中获得函数或格式的帮助.在此先感谢您的帮助.html?help()R.tex.Rnw.tex

?lm
Run Code Online (Sandbox Code Playgroud)

Das*_*son 6

我在Noam Ross找到了一篇博文,在这里引用了这个问题:http://www.r-bloggers.com/printing-r-help-files-in-the-console-or-in-knitr-documents/

该功能可通过github在Noam的包装noamtools中获得

 library(devtools)
 install_github("noamtools", "noamross")
 library(noamtools)
 help_console(lm, format = "latex")
Run Code Online (Sandbox Code Playgroud)

为了子孙后代,他们创造的功能是

help_console <- function(topic, format=c("text", "html", "latex", "Rd"),
                         lines=NULL, before=NULL, after=NULL) {  
  format=match.arg(format)
  if (!is.character(topic)) topic <- deparse(substitute(topic))
  helpfile = utils:::.getHelpFile(help(topic))

  hs <- capture.output(switch(format, 
                              text=tools:::Rd2txt(helpfile),
                              html=tools:::Rd2HTML(helpfile),
                              latex=tools:::Rd2latex(helpfile),
                              Rd=tools:::prepare_Rd(helpfile)
                              )
                      )
  if(!is.null(lines)) hs <- hs[lines]
  hs <- c(before, hs, after)
  cat(hs, sep="\n")
  invisible(hs)
}
Run Code Online (Sandbox Code Playgroud)

像这样使用它来获得乳胶输出

help_console(lm, format = "latex")
Run Code Online (Sandbox Code Playgroud)