Setting graphics to disappear with null device?

Is there a way to set output to "go to" the null graphics device? In other words, to not appear at all. The idea is to give a command such that subsequent plots won't appear and won't cause an error. My understanding is that setting the graphics device to 1 won't do the trick, because subsequent plots reset the graphics device when the current device is 1. (The situation is that code is going to be sourced which we have no control over. We just don't want the plots to appear.)

I found this :
R.devices - Into the Void (
worth a try.
But not sure if it would guarantee that source code you dont control could set your devices such that they would plot ... so probably worth adversarially testing it against that 'attack'.

1 Like

Thank you @nirgrahamuk. Will give it a try.

We are actually in a weird situation. We use "autograder" code on a product called GradeScope to grade submitted student code. The server is "headless," which seems to mean that any attempt to open a graphics window causes the code to bomb. We don't really have to worry much about "adversarial" attacks--although I appreciate the warning. We're just trying to reduce the number of bombs when students do things that are perfectly reasonable.

While nirgrahamuk's suggestion seems the most robust in an "autograder" context, it is also worth noting a simple solution for one-off cases, which doesn't require any package:


Where base::nullfile() automatically sends to the void.

(of course, here I used png(), any other device works as long as you save into null)

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.