title: Poly2nb - How to get rid of empty geometries in r
body: <p>I have r code that I am using to compute Getis-ord Gstatistics. I typically create my shapefile in GIS, then import into r to use with the code. I recently needed to make an edit to my shapefile, which I did in GIS and imported into sas as usual:</p>
  <pre><code>tract&lt;-st_read(&quot;CBSA2022.shp&quot;)
  </code></pre>
  <p>My issue is with the loop portion of my code and the poly2nb feature. Currently it is written as:</p>
  <pre><code>for (CBSA in CBSAs) {
    temp &lt;- tract[ tract$CBSAFP == CBSA, c(&quot;JOIN_ID&quot;, variable_of_int)]
    names(temp)[2] &lt;- 'black_pop'
    #We create the weight matrices within each CBSA now
    #We check that there are more than one tract in the CBSA
    if ((nrow(temp) &gt; 1)) {
      q1&lt;-poly2nb(temp, queen = queen)
  if (self_include){ q1 &lt;- include.self(q1) }
  </code></pre>
  <p>Before editing my shapefile in GIS, this worked perfectly with no errors. Now, I receive this error message:</p>
  <p>Error in poly2nb(temp, queen = queen) : Empty geometries found</p>
  <p>What do you think could be different about my shapefile that I now get this error? And/or how can I fix this? The only difference between this shapefile and the original, is I had to define my spatial join differently when joining my data to spatial polygons in GIS.</p>
  <p>I haven't tried anything significant since I am not well versed in r. I did not create this code, but worked with a student (that is no longer available) to create it to be very user friendly for me to use. I've used it numerous times with different shapefiles before my recent edit, and it always worked, just not sure why I now have empty geometries or how to fix it.</p>