0

我是一位经验丰富的 R 和 knitr 用户,自 2012 年以来一直在使用这些,所以我是解决问题的老手,但这让我很难过。其实这个问题很关键。

这是可以正常工作的代码:

<<configure, eval=TRUE>>=
rm(list = ls())
library(knitr)
library(ggplot2)
library(tidyr)
@

这是导致问题的代码:

<<configure, eval=TRUE, dev='png', fig.width=4, fig.height=4>>=
rm(list = ls())
library(knitr)
library(ggplot2)
library(tidyr)
@

这是错误消息:

> knit2pdf("template.Rnw")


processing file: template.Rnw

  |                                                                       
  |                                                                 |   0%
  |                                                                       
  |.............                                                    |  20%
  ordinary text without R code


  |                                                                       
  |..........................                                       |  40%
label: configure (with options) 
List of 4
 $ eval      : logi TRUE
 $ dev       : chr "png"
 $ fig.width : num 4
 $ fig.height: num 4

Quitting from lines 43-47 (template.Rnw) 
Error in (function (filename = "Rplot%03d.png", width = 480, height = 480,  : 
  unable to start png() device
In addition: Warning messages:
1: In (function (filename = "Rplot%03d.png", width = 480, height = 480,  :
  unable to open file 'C:\Users\ccc31\AppData\Local\Temp\RtmpSwTCKI\file8e94649b2b62' for writing
2: In (function (filename = "Rplot%03d.png", width = 480, height = 480,  :
  opening device failed

我已经在这个文件上工作了至少六个星期,没有任何问题,但现在它莫名其妙地失败了。自从我上次运行它以来,有两件事发生了变化。(1) 我的 McAfee Total Protection 已更新。(2) 我的 Windows 10 操作系统安装了更新。(3) 其他东西可能已经改变,但我不知道它是什么。

我正在使用控制台运行 R x64 3.5.1 并运行上面显示的命令。这是我正在进行的一个关键项目,我只有几天的时间来完成它,所以任何帮助都将不胜感激。谢谢你。

4

1 回答 1

0

这不是解决方案,而是“修复”。(1) 保存历史文件后,我关闭了 R 控制台,以防万一。(2) 我删除了我的 .RData 文件。(3) 我重新启动了我的机器。(4) 我打开一个新的 R 控制台,导航到我的项目目录,然后运行我的脚本。

一切恢复正常。万岁!!!不过,我想知道错误的来源,但我会很高兴它工作。

于 2019-09-16T00:41:56.230 回答