简体   繁体   English

绘制编织错误:“无法启动 png() 设备”

[英]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.

相关问题 错误:无法启动 png() 设备 - Error : Unable to start png() device 无法导出绘图:R 代码执行错误/无法启动 png() 设备 - Unable to export plot: R code execution error/ unable to start png() device 无法启动 plot 名称的 png() 设备使用“粘贴”function 创建 - unable to start png() device for plot names create with "paste" function ggsave() 失败并在 png_dev(..., res = dpi, units = "in") 中出现错误:无法启动 png() 设备 - ggsave() fails with Error in png_dev(..., res = dpi, units = "in") : unable to start png() device jupyter 中的 r 图形 - 无法启动 png() 设备 - r graphs in jupyter - unable to start png() device R无法启动设备PNG - 功能()对于PNG是否为TRUE? - R unable to start device PNG - capabilities() has TRUE for PNG? 这是什么错误; “(函数(文件名 =“Rplot%03d.png”,宽度 = 480,高度 = 480,:无法启动 png() 设备)中的错误? - What is this error; "Error in (function (filename = "Rplot%03d.png", width = 480, height = 480, : unable to start png() device"? “ plotGoogleMaps启用启动设备png”错误 - “plotGoogleMaps enable to start device png” error R Markdown使用动态字符串扩展:无法启动png()设备时出现错误,没有明确的原因有时 - R Markdown Expanding with Dynamic String: Error unable to start png() device Shows Up Occasionally Without Clear Reason R Shiny 运行几个小时后无法启动 png 设备 - R Shiny unable to start png device after running a few hours
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM