Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Still getting error in dev.off() : cannot shut down device 1 (the null device)

Tags:

I am new to R so I dont exactly know what kind of information to provide to get help but here it goes: I get the error "Error in dev.off() : cannot shut down device 1 (the null device)" when I try to make a plot... any plot. My latest code is:

pdf("spec_accum_w_sample.pdf")
plot(specaccum(counts))
dev.off()

An empty pdf file and a plot get successfully produced but when I write dev.off() it does not write into the created pdf. Instead I get the error above. I have tried restarting RStudio as well as anything else suggested on this link: Error in dev.off() : cannot shut down device 1 (the null device). I have also tried the initial code suggested on the ticket to re-create the author's pie chart, but still get the same error despite trying all of the suggestions

I do not find any other place that addresses this specific error. I am running R version 3.4.4 (2018-03-15) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Sierra 10.12.6

Is there anything else I can try? Am I supposed to install something or update something to get dev.off() to work?

like image 846
Angelina Avatar asked Apr 25 '18 17:04

Angelina


2 Answers

Try this: (It worked for me but will shut down any plotting device open).

while (!is.null(dev.list()))  dev.off()
like image 200
Joke O. Avatar answered Sep 28 '22 18:09

Joke O.


Make sure your pdf is produced in your working directory. Run getwd() to check what's the working directory. If the pdf is not there, change the working directory to where the pdf is produced with setwd("/my/working/directory").

Alternatively try opening a new device and then create a pdf, a plot, and write it into the pdf:

dev.new()
pdf("spec_accum_w_sample.pdf")
plot(specaccum(counts))
graphics.off()
like image 21
PiotrWolkowski Avatar answered Sep 28 '22 18:09

PiotrWolkowski