[英]Plot knitting error : “unable to start png() device”
I'm using Rmarkdown to produce beautiful documents (like with LaTex), but there is a problem I can't solve.我正在使用 Rmarkdown 生成漂亮的文档(如使用 LaTex),但有一个我无法解决的问题。
I'm printing graph in the following way:我正在以下列方式打印图形:
```{r p(s|r)}
pleft=function(x, p=0.5){dnorm(x, mean=35, sd = 10)*p/(dnorm(x, mean=35, sd
= 10)*p+dnorm(x, mean=65, sd = 10)*(1-p))}
pright=function(x, p=0.5){dnorm(x, mean=65, sd = 10)*(1-p)/(dnorm(x,
mean=35, sd = 10)*p+dnorm(x, mean=65, sd = 10)*(1-p))}
pleft50= function(x){pleft(x, 0.5)}
pright50=function(x){pright(x, 0.5)}
curve(pleft50, from=-10, to=110, xlab="Firing Rate r (Hz)", ylab="p(s|r)",
col="red", lwd=2)
curve(pright50, from=-10, to=110, xlab="Firing Rate r (Hz)", ylab="p(s|r)",
col="blue", lwd=2, add=TRUE)
legend("right", legend = c("p(Left|r)","p(Right|r)"), col=c('red', 'blue'),
lwd = 2)
title("Posteriors")
```
This has worked in the same way in every precedent code chunk and document, but now it raises this error when I knit the document:这在每个先例代码块和文档中都以相同的方式工作,但是现在当我编织文档时它会引发此错误:
Error in png(..., res = dpi, units = "in") : unable to start png() device Calls: ... in_dir -> plot2dev -> do.call -> -> png In addition: Warning messages: 1: In png(..., res = dpi, units = "in") : unable to open file 'ExSheet4_files/figure-html/name of my chunk-1.png' for writing 2: In png(..., res = dpi, units = "in") : opening device failed
png(..., res = dpi, units = "in") 中的错误:无法启动 png() 设备调用:... in_dir -> plot2dev -> do.call -> -> png 另外:警告消息: 1: 在 png(..., res = dpi, units = "in") : 无法打开文件 'ExSheet4_files/figure-html/name of my chunk-1.png' 2: 在 png(.. ., res = dpi, units = "in") : 打开设备失败
I've tried a anything I know, it raise it as soon as curve(pleft50,...
is called.我已经尝试了任何我知道的方法,它会在调用
curve(pleft50,...
) 后立即将其升高。
Thank you for your answer and sorry for my english !谢谢你的回答,对不起我的英语!
It doesn't like the p(s|r)
in the first line -- it's trying to create a file for writing and it's failing there.它不喜欢第一行中的
p(s|r)
—— 它试图创建一个用于写入的文件,但在那里失败了。 If you remove it, eg:如果删除它,例如:
---
title: "Untitled"
date: "April 14, 2018"
output:
html_document: default
word_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
pleft=function(x, p=0.5){dnorm(x, mean=35, sd = 10)*p/(dnorm(x, mean=35, sd
= 10)*p+dnorm(x, mean=65, sd = 10)*(1-p))}
pright=function(x, p=0.5){dnorm(x, mean=65, sd = 10)*(1-p)/(dnorm(x,
mean=35, sd = 10)*p+dnorm(x, mean=65, sd = 10)*(1-p))}
pleft50= function(x){pleft(x, 0.5)}
pright50=function(x){pright(x, 0.5)}
curve(pleft50, from=-10, to=110, xlab="Firing Rate r (Hz)", ylab="p(s|r)",
col="red", lwd=2)
curve(pright50, from=-10, to=110, xlab="Firing Rate r (Hz)", ylab="p(s|r)",
col="blue", lwd=2, add=TRUE)
legend("right", legend = c("p(Left|r)","p(Right|r)"), col=c('red', 'blue'),
lwd = 2)
title("Posteriors")
```
You get this:你得到这个:
The described error occurs, when you are knitting plots within named code chunks, and the name of the chunk does not lead to a valid path name during knitting process.当您在命名的代码块中编织图时,会发生所描述的错误,并且在编织过程中块的名称不会导致有效的路径名。
That is, during the knitting process the plots are written into a temporary path which contains the name of the code chunk, ergo this name should contain only characters that are valid for path names, which was not true for the used character |
也就是说,在编织过程中,将绘图写入包含代码块名称的临时路径中,因此该名称应仅包含对路径名称有效的字符,而对于使用的字符则不正确
|
. . One should avoid to use white characters for
chunk names
as well.还应避免在
chunk names
使用白色字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.