【问题标题】:R code mcmcplots functionR代码mcmcplots函数
【发布时间】:2012-10-25 22:22:08
【问题描述】:

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

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

【问题讨论】:

  • 可以try(mcmcplot())解决你的问题吗?

标签: r plot mcmc


【解决方案1】:

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

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)

【讨论】:

    【解决方案2】:

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

    browseURL <- identity
    

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

    rm(browseURL)
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-06
      • 2014-05-13
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2014-03-14
      • 2015-10-02
      • 1970-01-01
      相关资源
      最近更新 更多