title: Rstudio won't produce plots: Shadow graphics device error: r error 4 (R code execution error)
body: <p>I've seen this error reported several times but there's never been a solution. I'm using Rstudio for desktop in a Windows 10. I'm not able to produce plots in Rstudio. Plots in R command line work perfectly; in Rstudio if I open a device like in <code>png("myplot.png"); plot(1); dev.off()</code>, that works perfectly.</p>
  
  <p>But if I just want to produce a plot in Rstudio (like plot(1) for example), I get the following error:</p>
  
  <pre><code>Error in plot.new() : 
   Shadow graphics device error: r error 4 (R code execution error)
  In addition: Warning messages:
  1: In grDevices:::png("C:/Users/marco/AppData/Local/Temp/RtmpgfCSkE/c79b28dca0464804b619980ea7a4d95e.png", :
   unable to open file 'C:/Users/marco/AppData/Local/Temp/RtmpgfCSkE/c79b28dca0464804b619980ea7a4d95e.png' for writing
  2: In grDevices:::png("C:/Users/marco/AppData/Local/Temp/RtmpgfCSkE/c79b28dca0464804b619980ea7a4d95e.png", :
   opening device failed
  3: In grDevices:::png("C:/Users/marco/AppData/Local/Temp/RtmpgfCSkE/c79b28dca0464804b619980ea7a4d95e.png", :
   unable to open file 'C:/Users/marco/AppData/Local/Temp/RtmpgfCSkE/c79b28dca0464804b619980ea7a4d95e.png' for writing
  4: In grDevices:::png("C:/Users/marco/AppData/Local/Temp/RtmpgfCSkE/c79b28dca0464804b619980ea7a4d95e.png", :
   opening device failed
  </code></pre>
  
  <p>I tried unistalling RStudio and R, cleaning the registry, and installing again but still the same. This happened after installing R and Rstudio in a new machine. Never had this problem with Rstudio at Windows 10 before.</p>
  
  <p>Any help would be highly appreciated, I can't find any useful hints anywhere.</p>
  
  <pre><code>&gt; sessionInfo()
  R version 3.3.1 (2016-06-21)
  Platform: x86_64-w64-mingw32/x64 (64-bit)
  Running under: Windows &gt;= 8 x64 (build 9200)
  
  locale:
  [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C LC_TIME=English_United States.1252
  
  attached base packages:
  [1] stats graphics grDevices utils datasets methods base
  
  loaded via a namespace (and not attached):
  [1] tools_3.3.1
  &gt; capabilities()
   jpeg png tiff tcltk X11 aqua http/ftp sockets libxml fifo cledit iconv NLS profmem cairo ICU 
   TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE 
  long.double libcurl 
   TRUE TRUE 
  </code></pre>