在我重新启动 RStudio 之前无法打开保存的绘图

Can't open saved plot until I restart RStudio

当我保存这样的情节时:

png("test.png")
plot(1:10)
dev.off()

我有时无法打开文件,直到我重新启动 RStudio。 Windows 10 给我错误信息:

"It looks like you don't have permission to view this file. Check the permissions and try again."

如何在不重新启动 RStudio 和丢失我的环境的情况下在另一个应用程序中打开文件?

您可能通过之前的命令打开了一个图形设备(上面的代码不是导致问题的原因,而是它出现的地方)。 RStudio guidance suggests:

To reset your graphics device, call the following code from the console:

dev.off()

注:

这将删除 RStudio 绘图窗格中的当前绘图。 如果你 打开多个图形设备,重复此命令直到 输出显示空设备。

运行dev.off()反复直到returns"null device."