【问题标题】:helpExtract function does not work in R 3.1.1 and knitr 1.6.10helpExtract 函数在 R 3.1.1 和 knitr 1.6.10 中不起作用
【发布时间】:2026-01-16 12:55:01
【问题描述】:

我从@AnandaMahto 编写的here 中获取了以下代码。此功能之前运行良好,但停止使用 R 3.1.1knitr 1.6.10

\documentclass{article}

\begin{document}

<<echo=FALSE>>=
library(devtools)
source_gist("https://gist.github.com/mrdwab/7586769")
@

\Sexpr{knit_child(textConnection(helpExtract(cor, section="Arg", type = "s_text")),
options = list(tidy = FALSE, eval = FALSE))}

\Sexpr{knit_child(textConnection(helpExtract(cor, type = "s_code")), 
options = list(tidy = FALSE, eval = FALSE))}

<<tidy=TRUE>>=
## normal R code
args(lm)
@

\end{document}

【问题讨论】:

  • 看看@AnandaMahto 有没有解决办法。
  • 奇怪。如果函数的内容是逐行运行的,它们似乎输出了预期的内容....
  • @AnandaMahto:对你有用吗?
  • 我认为source_gist 有问题。如果我在 .Rnw 中定义函数,这将有效。
  • @kohske,为什么会这样?

标签: r latex knitr sweave


【解决方案1】:

作为一种临时解决方案,您可以通过避免 library(devtools) 来做到这一点

<<echo=FALSE>>=
devtools::source_gist("https://gist.github.com/mrdwab/7586769")
@

但根本的解决办法是修改helpExtract函数。 在第 3 行,utils:::.getHelpFile(help(A)) 应该是 utils:::.getHelpFile(utils::help(A))

这是由一些deparsesubstitute 链引起的。 我不确定这是否是devtools 的错误,但至少我认为这是devtools 包的不良行为,所以我会让@hadley 知道这种行为。

【讨论】:

  • +1 用于侦查。正如我在 cmets 中提到的,似乎从包中加载函数也可以。
  • 是的,那是因为包内搜索路径不同,所以即使用户调用library(devtools),包内help的调用指向utils::help
  • 酷。然后我将修改函数以明确引用utils::help