此问题has been reported并在rmarkdown存储库中回答。在这里,我只是试图解释为什么它不起作用的技术原因。
从帮助页面?neuralnet::plot.nn
:
Usage
## S3 method for class 'nn'
plot(x, rep = NULL, x.entry = NULL, x.out = NULL,
....
Arguments
...
rep repetition of the neural network. If rep="best", the repetition
with the smallest error will be plotted. If not stated all repetitions
will be plotted, each in a separate window.
从源代码(v1.33中):
> neuralnet:::plot.nn
function (x, rep = NULL, x.entry = NULL, x.out = NULL, radius = 0.15,
....
{
....
if (is.null(rep)) {
for (i in 1:length(net$weights)) {
....
grDevices::dev.new()
plot.nn(net, rep = i,
....
}
}
予省略如上所述使用....
的irrelvant信息。基本上如果你没有指定rep
,neuralnet:::plot.nn
会打开新的图形设备绘制阴谋。这将打破knitr的图形记录,因为
- 它打开图形设备,但没有要求他们打开记录(通过
dev.control(displaylist = 'enable')
);
- knitr默认使用自己的设备记录图形;如果用户打开新设备,则不能保证可以通过knitr节省新的地块。一般来说,我不打算在绘图功能中操纵图形设备。
我不是neuralnet包的作者,但我建议作者降dev.new()
,或者至少使其有条件的,例如
if (interactive()) grDevices::dev.new()
我猜dev.new()
调用的意图很可能显示在新窗口中地块,但实在是没有保证用户可以看到窗口。 R会话的默认图形设备是窗口/屏幕设备(如果可用,例如x11()
或quartz()
),但用户或程序包作者更改默认设备的可能性很大。
我建议条件interactive()
,因为对于非交互式R会话,打开新的(默认情况下,off-screen)设备可能没有多大意义。
试试''netnet :: plot(net)'看看会发生什么。我一直在使用'rbokeh'和'DT',并且在块内有类似的问题,但在另一个窗口的脚本中完全没有问题。它感觉就像某种方式的基本功能是如此。这可能不是你正在发生的事情,但它为我工作,值得一试。 – sconfluentus
最初我认为问题是没有'neuralnet :: plot',但我看到运行大块而不是编织会产生一个阴谋。奇怪的确如此。 – neilfws
此前已有报道:https://github.com/rstudio/rmarkdown/issues/856 –