title: Why is a map not displayed when I call leaflet in a function
body: <p>I want to customize some plot-functions using leaflet. My problem is, that the maps are not displayed in the html as soon as I use leaflet inside a function. Does anybod know a solution?</p>
  
  <p>Here is an example and what I have tried:</p>
  
  <pre><code>Save this as .Rmd
  ```{r, c1, echo = FALSE}
  map &lt;- function() {
    library(leaflet)
    m &lt;- leaflet(width = "100%") %&gt;%
      addTiles(group = "OSM") %&gt;%
      addProviderTiles("Stamen.TonerLite") %&gt;%
      addLayersControl(
        baseGroups = c("OSM", "Stamen.TonerLite"))
    return(m)
  }
  
  map_poa &lt;- function() {
    m &lt;- map()
    m %&gt;% addCircleMarkers(lat = c(47, 47.5),
                           lng = c(8, 8.5),
                           stroke = FALSE,
                           radius = 10,
                           fillOpacity = 0.8,
                           clusterOptions = markerClusterOptions())
      print(m)
    return(m)
  }
  ```
  </code></pre>
  
  <p>One of those plot should work somehow. What I tried:</p>
  
  <pre><code>Add this chunk to the above .Rmd
  ```{r, c2, echo = FALSE}
  # map() # Works
  map_poa() # map without content
  # print(map_poa()) # Does not work at all (Nothing shown)
  # plot(map_poa()) # Does not work (Throws error)
  ```
  </code></pre>
  
  <p>Without a function, everything gets displayed:</p>
  
  <pre><code>Add this chunk to the above .Rmd
  ```{r, c3, echo = FALSE}
  m &lt;- map()
  m %&gt;% addCircleMarkers(lat = c(47, 47.5),
                         lng = c(8, 8.5),
                         stroke = FALSE,
                         radius = 10,
                         fillOpacity = 0.8,
                         clusterOptions = markerClusterOptions())
  print(m)
  ```
  </code></pre>