Suppress warning: (‘future_lapply-*’) added, removed, or modified devices
for ggExtra::ggMarginal
#788
-
When using Reproducible Example:
I received the following warning (Linux HPC). The warning is repeated with the number of cores used
In the previous example, I only created the plot object without explicitly saving the plot to a file. Running the code resulted in a redundant PDF file saved to the working directory Interestingly, when I apply the function again and again, I receive no warnings
Is it possible to disable this warning without using suppressWarnings? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 3 replies
-
Those warnings are by design and there to make us aware of graphical devices being opened and left behind without our knowledge. So, this works exactly as wanted. This check was introduced in future 1.40.0. Now, the problem is that library(future)
library(ggplot2)
# Sample data
data <- data.frame(x = rnorm(100), y = rnorm(100))
plot <- ggplot(data, aes(x, y)) + geom_point()
f <- future({
ggExtra::ggMarginal(p = plot, type = "histogram")
})
v <- value(f) If you run this with I'm not sure what you want to do with that plot being generated, but if you want to return the plot object and display it locally, you can do something like: f <- future({
## Open a temporary PDF graphics device that writes to void
pdf(nullfile())
on.exit(dev.off())
ggExtra::ggMarginal(p = plot, type = "histogram")
})
plot <- value(f) That will open a temporary PDF graphics device for ggExtra to use and then shut it down on exit. You can then plot the graph locally by: print(plot) See also my 2016-10-11 blog post ' Remote Processing Using Futures' (https://www.jottr.org/2016/10/11/future-remotes/), which illustrates the idea of generating graphs remotely, but displaying them locally.
The reason for this is that ggExtra opened a PDF graphics device, which writes to that |
Beta Was this translation helpful? Give feedback.
-
Thanks @HenrikBengtsson. This did not work for me. I would like to prepare many marginal plots in parallel, then I will arrange them using patchwork in different ways. I need to return the ggplot object or a tibble with a list column containing the ggplot object. Original function:
Running the same function again gave no warnings!
Using
Using a valid file path did not help as well.
|
Beta Was this translation helpful? Give feedback.
-
The problem seems not to be from Is it possible to suppress this specific warning using the I used
|
Beta Was this translation helpful? Give feedback.
-
I think I found a temporary solution that disables the
|
Beta Was this translation helpful? Give feedback.
-
Agree, it appear that the graphics devices is opened by
Thanks for the follow up. I can reproduce this using your example. It turns out that these warning messages are slightly different from the original ones. The "... devices differ: index=3, before=‘NA’, after=‘’" part triggered my attention. It turns out that there was a thinko/bug in the code comparing graphics devices before and after evaluating the future. It failed to prune off devices with empty names (after=''), which triggered this false-positive warning. I've fixed this in the develop version of future. Please retry with: remotes::install_github("futureverse/future", ref = "develop") Regarding your strategy to muffle these warnings: Putting aside that the The analogue is a bit like when you cook and the food in one of the pan is overheated producing smoke. The smoke alarm goes off. The natural instinct is to silence the smoke alarm (= muffle the warnings), but the real solution is to turn off the stove and remove the smoking pan (= prevent spurious graphics devices from being opened). It's also not uncommon that people take out the battery (= disable the checks) of the smoke alarm so they can keep cooking, but that comes with the risk of forgetting to put the battery back in when done cooking. (*) Yes, there are R options to disable these type of checks. |
Beta Was this translation helpful? Give feedback.
-
Thanks @HenrikBengtsson for your detailed response and example. I installed
|
Beta Was this translation helpful? Give feedback.
-
I missed that. Thanks. This solved the issue, with no warnings on unclosed devices. But I still have these warnings. I tested with another Windows PC and found that an earlier version of future did not show these warnings, but installing the development version from GitHub shows these warnings.
|
Beta Was this translation helpful? Give feedback.
-
I opened a new discussion here: #790. |
Beta Was this translation helpful? Give feedback.
Agree, it appear that the graphics devices is opened by
ggplot2::ggplotGrob()
, whichggExtra::ggMarginal()
calls internally.