Question

[Solved] Error in dev.off() : cannot shut down device 1 (the null device)

I am new to R programming and I got hit with this error when I tried to run the code. This simply creates a pie chart with some data. Can anyone explain to me why I am getting this error and what it means?

1) I am running windows
2) Version 3.4.0
3) I am using RGui desktop
4) R version 3.4.0

# Create data for the graph.
x <- c(21, 62, 10, 53)
labels <- c("London", "New York", "Singapore", "Mumbai")

# Give the chart file a name.
png(file = "city_title_colours.jpg")

# Plot the chart with title and rainbow color pallet.
pie(x, labels, main = "City pie chart", col = rainbow(length(x)))

# Save the file.
dev.off()
Enquirer: Andrew

||

Solution #1:

try

while (!is.null(dev.list()))  dev.off()
Respondent: Andrew

Solution #2:

I had this situation and resolved it by running the following 2 or 3 times:

dev.set(dev.next())

The console should eventually spit out:

quartz_off_screen 
                3

Once you see this, the plots will render.

P.S. you can probably use dev.set(dev.prev()) in the same way.

Respondent: farid khafizov

Solution #3:

In my case the reason for the error was also quite silly. In case anyone runs into the same issue…

dev.off

will result in:

function (which = dev.cur()) 
{
    if (which == 1) 
        stop("cannot shut down device 1 (the null device)")
    .External(C_devoff, as.integer(which))
    dev.cur()
}
<bytecode: 0x0000000028e62bd8>
<environment: namespace:grDevices>

Do not forget the function brackets:

dev.off()
Respondent: awags1

Solution #4:

Turns out that the only problem with this was with where the file was trying to save to. I altered the code to save to a different directory and it worked fine

Respondent: ThomDietrich

Solution #5:

When I had this issue, I was attempting to run dev_off() as well with an attempted file being created from the Rchunk I was dealing with. To fix it, I highlighted the entire chunk and tried to rerun it. It didn’t say that above so I wanted to add as a possible help to the issue if needed.

Respondent: Andrew

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy