title: How can I filter parts of a SpatialPolygonDataFrame?
body: <p>I would like if there is a simple solution to filter a SpatialPolygonDataFrame in R. Imagine I have many polygons but I only want to select some of them to plot them using <code>leaflet</code></p>
  
  <p>My data comes from <a href="https://www.data.gouv.fr/fr/datasets/contours-iris/" rel="nofollow">data.gouv.fr</a></p>
  
  <p>Here is my <a href="https://gist.github.com/pachevalier/8bc7e6dfbb33f5e956b1" rel="nofollow">gist</a> for loading the data into R.</p>
  
  <p>If I want to draw only one polygon in <code>leaflet</code>, I filter the <code>@data</code> part of my SpatialPolygonDataFrame, get the id</p>
  
  <pre><code>&gt; ign_shape_iris@data %&gt;% 
  +   filter(DCOMIRIS == "606120301")
   DEPCOM NOM_COM IRIS  DCOMIRIS               NOM_IRIS TYP_IRIS  id 
  1  60612  Senlis 0301 606120301 Vald'Aunette-Gateliere        H 790
  </code></pre>
  
  <p>Then I plot only the polygon I want : </p>
  
  <pre><code>leaflet(ign_shape_iris@polygons[[790]]) %&gt;% 
   addTiles() %&gt;%
   addPolygons()
  </code></pre>
  
  <p>I'm sure there is a better solution.</p>