title: rmarkdown error with ggplot and png
body: <p>I have tried (in vain) to produce a chart with ggplot in Rmarkdown. 
  The code is the following:</p>
  
  <pre><code>```{r,echo=FALSE}
  #fig.width=12,fig.height=6
  panel2$PlotSize&lt;-round(log(panel2$BSFA0200),0)- min(round(log(panel2$BSFA0200),0))+1# set size of dots
  panel2$PlotSize[panel2$PlotSize==-Inf]&lt;-NA
  panel2$PlotColour&lt;-ifelse(panel2$PlotSize&lt;7,1,panel2$PlotSize)
  panel2$PlotSize&lt;-as.factor(panel2$PlotSize)
  panel2$PlotColour&lt;-as.factor(panel2$PlotColour)
  
  g1&lt;-ggplot(data=panel2,aes(x=NFR,y=PROF7*100,size=PlotSize,colour=PlotSize))+ geom_point()
  
  g1
  
  ```
  </code></pre>
  
  <p>Out of knits this works fine, however when executed within a Rmd file (either as html or pdf) I always get this error message</p>
  
  <pre><code>processing file: 1Profti_model.Rmd
    |..                                                               |   4%
    ordinary text without R code
  
    |.....                                                            |   8%
  label: setup (with options) 
  List of 1
   $ include: logi FALSE
  
    |........                                                         |  12%
    ordinary text without R code
  
    |..........                                                       |  15%
  label: unnamed-chunk-1 (with options) 
  List of 3
   $ echo   : logi FALSE
   $ warning: logi FALSE
   $ message: logi FALSE
  
  
  Attaching package: 'dplyr'
  
  The following objects are masked from 'package:stats':
  
      filter, lag
  
  The following objects are masked from 'package:base':
  
      intersect, setdiff, setequal, union
  
  Loading required package: zoo
  
  Attaching package: 'zoo'
  
  The following objects are masked from 'package:base':
  
      as.Date, as.Date.numeric
  
    |............                                                     |  19%
     inline R code fragments
  
    |...............                                                  |  23%
  label: unnamed-chunk-2 (with options) 
  List of 1
   $ echo: logi FALSE
  
    |..................                                               |  27%
    ordinary text without R code
  
    |....................                                             |  31%
  label: unnamed-chunk-3 (with options) 
  List of 1
   $ echo: logi FALSE
  
  Quitting from lines 98-109 (1Profti_model.Rmd) 
  Error in png(..., res = dpi, units = "in") : unable to start png() device
  Calls: &lt;Anonymous&gt; ... in_dir -&gt; plot2dev -&gt; do.call -&gt; &lt;Anonymous&gt; -&gt; png
  In addition: Warning messages:
  1: Removed 55 rows containing missing values (geom_point). 
  2: In png(..., res = dpi, units = "in") :
    unable to open file '1Profti_model_files/figure-html/unnamed-chunk-3-1.png' for writing
  3: In png(..., res = dpi, units = "in") : opening device failed
  
  Execution halted
  </code></pre>
  
  <p>I also tried to work around the problem by saving the chart in a png and load it as picture afterwards. Also no results (see <a href="https://stackoverflow.com/questions/34136738/error-with-loading-png-in-rmd-file">Error with loading png in Rmd file</a>)</p>
  
  <p>Thanks for your help</p>
  
  <p>UPDATE:</p>
  
  <p>Following the suggestions from some of you guys I added a different chunk name and I replicated the code from Davit on my data (see updated code).
  Unfortunately the error is still there. Interestingly, knitr cannot write a png but can write a csv in the same folder where the code is (I tested it). </p>
  
  <p>Finally, i tested running this very same code onto my C drive and (surprise!) it works. However, this is for me not very efficient as I don't want to be dependent on a specific machine and I need to share this work with others (so network drive is a must). Moreover, all other package/code work fine in the network drive, only this png() seems to be an issue. </p>
  
  <p>Thanks in advance for you help!
      ---
      title: New Document
      author: Me
      output:
        html_document
      ---</p>
  
  <pre><code>```{r prova,echo=FALSE, results='asis', message = FALSE, error = FALSE, warning= FALSE}
  #.libPaths("D:/xxxx/packages")
  require(ggplot2)
  
   panel2 &lt;- data.frame(BSFA0200 = rnorm(100),
                          NFR = rnorm(100),
                          PROF7 = rnorm(100))
  
  panel2$PlotSize&lt;-round(log(panel2$BSFA0200),0)- min(round(log(panel2$BSFA0200),0))+1# set size of dots
  panel2$PlotSize[panel2$PlotSize==-Inf]&lt;-NA
  panel2$PlotColour&lt;-ifelse(panel2$PlotSize&lt;7,2,panel2$PlotSize)
  
  write.csv(panel2[1:100,c('BSFA0200',"NFR","PROF7")],file="test.csv")
  
  g1 &lt;- ggplot(data = panel2,
               aes(x = NFR,
                   y = PROF7 * 100,
                   size = factor(PlotSize),
                   colour = factor(PlotSize)
                   ))
  
  g1 + geom_point()
  
  ```
  </code></pre>
  
  <p>Error output:</p>
  
  <pre><code>Loading required package: ggplot2
  
  Quitting from lines 9-32 (test.Rmd) 
  Error in png(..., res = dpi, units = "in") : unable to start png() device
  Calls: &lt;Anonymous&gt; ... in_dir -&gt; plot2dev -&gt; do.call -&gt; &lt;Anonymous&gt; -&gt; png
  In addition: Warning messages:
  1: Removed 35 rows containing missing values (geom_point). 
  2: In png(..., res = dpi, units = "in") :
    unable to open file 'test_files/figure-html/prova-1.png' for writing
  3: In png(..., res = dpi, units = "in") : opening device failed
  Execution halted
  </code></pre>
  
  <p>My knitr version is 1.11 (it should be the latest) and R version is 3.2.2</p>
  
  <pre><code>&gt; R.Version()
  $platform
  [1] "i386-w64-mingw32"
  
  $arch
  [1] "i386"
  
  $os
  [1] "mingw32"
  
  $system
  [1] "i386, mingw32"
  
  $status
  [1] ""
  
  $major
  [1] "3"
  
  $minor
  [1] "2.2"
  
  $year
  [1] "2015"
  
  $month
  [1] "08"
  
  $day
  [1] "14"
  
  $`svn rev`
  [1] "69053"
  
  $language
  [1] "R"
  
  $version.string
  [1] "R version 3.2.2 (2015-08-14)"
  
  $nickname
  [1] "Fire Safety"
  </code></pre>