r - 通过 noamtools 包中的 help_console 函数获取 R 函数帮助以在 .Rnw 文档中使用

标签 r function noamtools

我想使用 noamtools 包中的 help_console 函数将 R 函数的帮助包含到 .Rnw 文档中,其中可以从github安装使用以下命令:

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

下面给出了最小工作示例:

\documentclass{article}
\begin{document}

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

\end{document}

我没有得到正确的输出。

最佳答案

解决方案是包含该行

\usepackage{Rd}

在 .Rnw 文件的开头,然后使用

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

例如,将以下内容放入文件中,例如 test.Rnw 并编译以生成有关函数 mean 的文档。请注意,results=tex 确保由 R 生成的 Latex 代码实际上是像 Latex 代码一样创建的。

% 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}

生成的 pdf 看起来像这样,

mean

寻找here帮助我意识到需要包含 Rd.sty 文件。运行以下代码

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

您可以查看创建的名为 .Rd2xxxx 的目录,以查找 Rd2.tex,它显示了 R 创建的 Latex 文档文件中的内容。

关于r - 通过 noamtools 包中的 help_console 函数获取 R 函数帮助以在 .Rnw 文档中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34472935/

相关文章:

r - 如何处理完美拟合线性模型

r - 扩展组内所有可能组合的网格

r - 如何在R中的数据框中组合两列?

R:从深度嵌套的 XML 文件中将 XML 节点值提取到数据帧中

javascript - 使用 Applescript 从外部文件调用 Javascript 函数

python - 如何将打印输出分配给变量?

javascript - 自调用JavaScript函数会导致堆栈溢出异常吗