0

有没有办法让 Rmcmcplot()函数在调用时不打开浏览器?我需要在集群上运行我的 R 代码,如果mcmcplot()尝试打开浏览器,它会呕吐。

可以将输出转储到文件中吗?

4

2 回答 2

3

该函数将所有内容写入文件并在浏览器中打开它。如果您不想打开浏览器,我建议您编辑函数以传递是否要在浏览器中打开作为参数。您可以通过键入不带任何括号的名称来检索该函数。

mcmcplot

然后将该输出复制到编辑器并在开始时更改函数的名称并添加参数:

mcmcplotnew=function (mcmcout, parms = NULL, regex = NULL, random = NULL, 
    leaf.marker = "[\\[_]", dir = tempdir(), filename = "MCMCoutput", 
    extension = "html", title = NULL, heading = title, col = NULL, 
    lty = 1, xlim = NULL, ylim = NULL, style = c("gray", "plain"), 
    greek = FALSE,ShouldIPlotinbrowser=T)   #new argument here

然后还有更多的功能部分

然后最后有

    cat("\r", rep(" ", getOption("width")), "\r", sep = "")
    cat("\n</div>\n</div>\n", file = htmlfile, append = TRUE)
    .html.end(htmlfile)
    full.name.path <- paste("file://", htmlfile, sep = "")
    browseURL(full.name.path)
    invisible(full.name.path)
}

在您有 browsURL 行的地方,将其设置为:

if(ShouldIPlotinbrowser) { browseURL(full.name.path) }

然后在运行之前初始化该函数:

mcmcplotnew(whatever, usual, arguments,then,ShouldIPlotinbrowser=F)
于 2012-10-25T22:38:45.700 回答
2

源码,好像没有。那里有一个无条件的呼唤browseURL()。也许通过制作一个在全局命名空间中什么都不做的函数的虚拟版本,可以避免它的影响。

browseURL <- identity

这也可能会破坏其他浏览器活动,因此在mcmcplot调用之后,您可能想要

rm(browseURL)

或者,复制mcmcplot除该browseURL行之外的所有代码并改用该函数。

于 2012-10-25T22:40:43.407 回答