2

I want to include help of R functions into .Rnw document using help_console function from noamtools package which can be installed from github using the following comand:

devtools::install_github('noamross/noamtools', build_vignettes = TRUE)

Minimum working example is given below:

\documentclass{article}
\begin{document}

<< label=Test, echo=FALSE >>=
library(noamtools)
# help_console(topic="mean", format = "latex")
help_console(topic="mean", format = "Rd")
@ 

\end{document}

I'm not getting the correct output.

halfer
  • 19,824
  • 17
  • 99
  • 186
MYaseen208
  • 22,666
  • 37
  • 165
  • 309

1 Answers1

2

The solution is to include the line

\usepackage{Rd}

in the beginning of the .Rnw file and then use

help_console(topic="mean", format="latex")

For example, put the following in a file, say test.Rnw and compile to produce documentation about the function mean. Note that results=tex ensures that the Latex code produced by R is actually created like Latex code.

% devtools::install_github('noamross/noamtools', build_vignettes = TRUE)
\documentclass{book}
\usepackage{Rd} % Rstudio will be able to find this .sty file

\begin{document}

<<label=Test, results=tex>>=
library(noamtools)
help_console(topic="mean", format = "latex")
@ 

\end{document}

Which produces a pdf which looks like this,

mean

Looking here helped me realize that the Rd.sty file needed to be included. Running the following code

pack <- "ggplot2"
path <- find.package(pack)
system(paste(shQuote(file.path(R.home("bin"), "R")),
             "CMD", "Rd2pdf --no-clean", shQuote(path)))
# .Rd2xxxx directory created
# cd .Rd2xxxx

You can look inside the created directory named something like .Rd2xxxx to find Rd2.tex which shows what is put in the Latex documentation files which R creates.

Community
  • 1
  • 1
nathanesau
  • 1,681
  • 16
  • 27