Error in dev.off()

I repeatedly receive this Error.

Error in http://dev.off() : cannot shut down device 1 (the null device)

What is the problem?

Hi, and welcome!

Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers.

In this case, it's unclear how that error message is even possible. It simply is unrecognized in either the browser or R.

I just received this message in R Studio after I run this:

pdf("Results/CorHeatmap.pdf", width = 15, height = 15)
pheatmap(cor(ex))
dev.off()

Do you see the same with this code, in cut-and-paste ready reprex form?

library(pheatmap)

test <- matrix(rnorm(200), 20, 10)
    test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
    test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
    test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
    colnames(test) = paste("Test", 1:10, sep = "")
    rownames(test) = paste("Gene", 1:20, sep = "")
# Draw heatmaps
pdf("Results/pheat_test.pdf", width = 15, height = 15)
#> Error in pdf("Results/pheat_test.pdf", width = 15, height = 15): cannot open file 'Results/pheat_test.pdf'
pheatmap(test)

dev.off()
#> null device 
#>           1

Created on 2020-04-02 by the reprex package (v0.3.0)

What is the relation to my problem?

This is my problem and I dont know how to fix it

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

I'm trying to understand what causes the error message, which is necessary to know how to fix it.

The object ex in the code

pdf("Results/CorHeatmap.pdf", width = 15, height = 15)
pheatmap(cor(ex))
dev.off()

is invisible to me, which is the reason for creating the test object in my reprex. The reason I ask if you get a different result that shown is to isolate the problem.

For now, I can only guess. You would see the message if you tried to close a device that doesn't exist because, for example

pheatmap(cor(ex))

failed because ex was not in the namespace.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.