Unable to initiate png device Rnotebook

I have encountered this error trying to plot using rnotebook:

Error in (function (filename = "Rplot%03d.png", width = 480, height = 480, : unable to start png() device.

This is the code I am trying to run in Rnotebook

N <- 100
a <- rnorm(N)
b <- a + rnorm(N)
df1 <- data.frame(a, b)
ggplot(df1, aes(b)) + geom_histogram()

If I run it outside of rnotebook it works fine.

I have checked the issue in several other discussion boards but to no avail. Either the issue is beyond me or I am not able to really come down to a workaround. These are some the discussion boards I have checked:

I have to add that if at times I decide to just restart the R session or just close it altogether. Then the issue "disappears" and I can see the plots, but I don't think that is the desirable way it should work.

Any help regarding this issue will be highly appreciated.

Hello @ogorodriguez,
I'm sorry you are having this issue. Unfortunately, I was unable to reproduce it. For example, I was able to run the complete Rnotebook (saved as Untitled.Rmd) just fine:

---
title: "R Notebook"
output: html_notebook
editor_options: 
  chunk_output_type: inline
---

This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. 

```{r}
library(tidyverse)
N <- 100
a <- rnorm(N)
b <- a + rnorm(N)
df1 <- data.frame(a, b)
ggplot(df1, aes(b)) + geom_histogram()

Can you make a complete reprex? It may also help to see the sessionInfo().

1 Like

Try dev.off() if you don't want to restart RStudio.
I had a similar issue and the problem wouldn't disappear even after closing RStudio.
I somehow recall of reading something about devices not being closed properly.
Anyway dev.off did the trick and I was able to plot in RNotebook again.

1 Like