Hello all,
I have recently come across a peculiar error in R and I wanted to know if anyone here has any idea on how can it be solved. Here is some background- I am currently writing a pipeline which has multiple functions that are all "called" from a single central script. One of these functions involves generating multiple plots and saving them in a specified folder. I am using jpeg()
function in R for making these plots, here is an example:
#opening the barplot save code
jpeg(paste(backup_file, "plot.jpg", sep = ""), width = 12, height = 10, units = "in", res = 300)
#making enrichment plot
barplot(x)
#closing the connection
dev.off()
Here is the problem - when I "call" this function from the central script, it does not generate any plots (also does not give any errors). However, when I go to this function and run the code line-by-line, then the script does indeed generate the required plots.
Anyone know why this might be happening? Why a "call" to the function does not generate plot but running the code line-by-line does generate plot?
I am using R version - 4.3.1 (2023-06-16)
and Rstudio 2023.03.0+386 Cherry Blossom (server)
Thanks in advance for any help!
Does it work if you add a
dev.off()
before callingjpeg
?I tried doing that but it gives this error now -
Error in dev.off() : cannot shut down device 1 (the null device)
. Probably understandable because there is no open connection?