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:
png(nullfile())
plot(1)
dev.off()
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)