<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/r-devices-into-the-void/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.jottr.org/2018/07/21/suppressgraphics/"> JottR on R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a rel="nofollow" href="https://cran.r-project.org/package=R.devices" target="_blank">R.devices</a> 2.16.0 – <em>Unified Handling of Graphics Devices</em> – is on CRAN. With this release, you can now easily <strong>suppress unwanted graphics</strong>, e.g. graphics produced by one of those do-everything-in-one-call functions that we all bump into once in a while. To suppress graphics, the <strong>R.devices</strong> package provides graphics device <code>nulldev()</code>, and function <code>suppressGraphics()</code>, which both send any produced graphics into the void. This works on all operating systems, including Windows.</p>
<p><img src="https://i0.wp.com/www.jottr.org/post/guillaume_nery_into_the_void_2.gif?w=456&ssl=1" alt="" data-recalc-dims="1"><br>
<small><em><a rel="nofollow" href="https://www.youtube.com/watch?v=uQITWbAaDx0" target="_blank">Guillaume Nery base jumping at Dean’s Blue Hole, filmed on breath hold by Julie Gautier</a></em></small><br>
</p>
<h2>Examples</h2>
<pre><code>library(R.devices)
nulldev()
plot(1:100, main = &quot;Some Ignored Graphics&quot;)
dev.off()
</code></pre>
<pre><code>R.devices::suppressGraphics({
  plot(1:100, main = &quot;Some Ignored Graphics&quot;)
})
</code></pre>
<h2>Other Features</h2>
<p>Some other reasons for using the <strong>R.devices</strong> package:</p>
<ul>
<li>
<p><strong>No need to call dev.off()</strong> – Did you ever forgot to call <code>dev.off()</code>, or did a function call produce an error causing <code>dev.off()</code> not to be reached, leaving a graphics device open? By using one of the <code>toPDF()</code>, <code>toPNG()</code>, … functions, or the more general <code>devEval()</code> function, <code>dev.off()</code> is automatically taken care of.</p>
</li>
<li>
<p><strong>No need to specify filename extension</strong> – Did you ever switch from using <code>png()</code> to, say, <code>pdf()</code>, and forgot to update the filename resulting in a <code>my_plot.png</code> file that is actually a PDF file? By using one of the <code>toPDF()</code>, <code>toPNG()</code>, … functions, or the more general <code>devEval()</code> function, filename extensions are automatically taken care of – just specify the part without the extension.</p>
</li>
<li>
<p><strong>Specify the aspect ratio</strong> – rather than having to manually calculate device-specific arguments <code>width</code> or <code>height</code>, e.g. <code>toPNG(&quot;my_plot&quot;, { plot(1:10) }, aspectRatio = 2/3)</code>. This is particularly useful when switching between device types, or when outputting to multiple ones at the same time.</p>
</li>
<li>
<p><strong>Unified API for graphics options</strong> – conveniently set (most) graphics options including those that can otherwise only be controlled via arguments, e.g. <code>devOptions(&quot;png&quot;, width = 1024)</code>.</p>
</li>
<li>
<p><strong>Control where figure files are saved</strong> – the default is folder <code>figures/</code> but can be set per device type or globally, e.g. <code>devOptions(&quot;*&quot;, path = &quot;figures/col/&quot;)</code>.</p>
</li>
<li>
<p><strong>Easily produce EPS and favicons</strong> – <code>toEPS()</code> and <code>toFavicon()</code> are friendly wrappers for producing EPS and favicon graphics.</p>
</li>
<li>
<p><strong>Capture and replay graphics</strong> – for instance, use <code>future::plan(remote, workers = &quot;remote.server.org&quot;); p %&lt;-% capturePlot({ plot(1:10) })</code> to produce graphics on a remote machine, and then display it locally by printing <code>p</code>.</p>
</li>
</ul>
<h3>Some more examples</h3>
<pre><code>R.devices::toPDF(&quot;my_plot&quot;, {
  plot(1:100, main = &quot;Amazing Graphics&quot;)
})
### [1] &quot;figures/my_plot.pdf&quot;
</code></pre>
<pre><code>R.devices::toPNG(&quot;my_plot&quot;, {
  plot(1:100, main = &quot;Amazing Graphics&quot;)
})
### [1] &quot;figures/my_plot.png&quot;
</code></pre>
<pre><code>R.devices::toEPS(&quot;my_plot&quot;, {
  plot(1:100, main = &quot;Amazing Graphics&quot;)
})
### [1] &quot;figures/my_plot.eps&quot;
</code></pre>
<pre><code>R.devices::devEval(c(&quot;png&quot;, &quot;pdf&quot;, &quot;eps&quot;), name = &quot;my_plot&quot;, {
  plot(1:100, main = &quot;Amazing Graphics&quot;)
}, aspectRatio = 1.3)
### $png
### [1] &quot;figures/my_plot.png&quot;
### 
### $pdf
### [1] &quot;figures/my_plot.pdf&quot;
### 
### $eps
### [1] &quot;figures/my_plot.eps&quot;
</code></pre>
<h2>Links</h2>
<ul>
<li>R.devices package:
<ul>
<li>CRAN page: <a rel="nofollow" href="https://cran.r-project.org/package=R.devices" target="_blank">https://cran.r-project.org/package=R.devices</a></li>
<li>GitHub page: <a rel="nofollow" href="https://github.com/HenrikBengtsson/R.devices" target="_blank">https://github.com/HenrikBengtsson/R.devices</a></li>
</ul>
</li>
</ul>
<h2>See also</h2>
<ul>
<li><a rel="nofollow" href="https://www.jottr.org/2016/07/02/future-user2016-slides/" target="_blank">A Future for R: Slides from useR 2016</a>, 2016-07-02
<ul>
<li>See Slide 17 for an example of using <code>capturePlot()</code> remotely and plotting locally</li>
</ul>
</li>
</ul>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.jottr.org/2018/07/21/suppressgraphics/"> JottR on R</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/-4QFvbreXzk" height="1"></a></div>