使用noamtools R包中的help_控制台函数获取R函数的帮助

使用noamtools R包中的help_控制台函数获取R函数的帮助,r,github,tex,noamtools,R,Github,Tex,Noamtools,我可以通过以下方式从FrF2软件包获得R 3.1.2关于Yates功能的帮助: ?FrF2::Yates 现在我想通过noamtools R软件包中的help\u控制台功能获得.tex格式的帮助。我尝试了此代码,但不起作用: help_console(topic="Yates", format = "latex") 及 可以使用以下命令从github`获取noamtools R包: library(devtools) install_github("noamtools", "noamross

我可以通过以下方式从
FrF2
软件包获得
R 3.1.2
关于
Yates
功能的帮助:

?FrF2::Yates
现在我想通过
noamtools R
软件包中的
help\u控制台
功能获得
.tex
格式的帮助。我尝试了此代码,但不起作用:

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

可以使用以下命令从github`获取noamtools R
包:

library(devtools)
install_github("noamtools", "noamross")
library(noamtools)

这里的问题在于基本包
utils
中的函数
help
。您有两个包,它们都在导出具有相同名称的函数。具体来说,
DoE.base
FrF2
都导出
Yates
,因此
help
不加载Rd文件;相反,它希望您在不同的文件之间进行选择。但是控制台不知道如何处理这个问题。通过向
帮助控制台
添加一个
参数,将包名向下传递到
帮助
,可以很容易地纠正这一问题。要在特定的R会话中创建并实现此目标,您可以使用:

fixInNamespace("help_console", "noamtools")
要加载脚本编辑器,您可以将
help\u console
的定义更改为以下内容:

function (topic, format = c("text", "html", "latex", "Rd"), lines = NULL, 
    before = NULL, after = NULL, package = NULL) 
{
    format = match.arg(format)
    if (!is.character(topic)) 
        topic <- deparse(substitute(topic))
    helpfile = utils:::.getHelpFile(help(topic, package = (package)))
    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)
}

为了将其合并到
noamtools
,我发出了一个pull请求,要求对其进行更改。你可以看到。现在它已合并到GitHub上的主repo中,因此您可以按正常方式安装。

修改
help\u控制台
功能,以便指定软件包?
function (topic, format = c("text", "html", "latex", "Rd"), lines = NULL, 
    before = NULL, after = NULL, package = NULL) 
{
    format = match.arg(format)
    if (!is.character(topic)) 
        topic <- deparse(substitute(topic))
    helpfile = utils:::.getHelpFile(help(topic, package = (package)))
    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)
}
str(capture.output(help_console(topic="Yates", format = "latex", package="FrF2")))
## chr [1:139] "\\HeaderA{utilitiesCat}{ \\textasciitilde{}\\textasciitilde{} Internal utility functions and a user-visible constant for workin"| __truncated__ ...
str(capture.output(help_console(topic="Yates", format = "latex", package="DoE.base")))
## chr [1:65] "\\HeaderA{block.catlg3}{Catalogues for blocking full factorial 2-level and 3-level designs,  and lists of generating columns fo"| __truncated__ ...