title: R: "Object of type 'S4' is not subsettable" when using foreach loop
body: <p>I deal with some shapefiles and rasters. </p>
  
  <p>When I execute my script line by line (or part by part), everything runs as expected. However, if I execute it as a whole (either source it or STRG+A and then STRG+ENTER), it throws an error in the following section:</p>
  
  <pre><code># ... some code
  
  list = list()
  
  list = foreach(i = seq(from = 9, to = 80, by = 5)) %dopar% {
  
      df[which(df@data$column.name &gt; i), ] 
  } 
  
  # ... some code
  </code></pre>
  
  <p>Error message: <code>Error in { : task 2 failed - "Object of type 'S4' is not subsettable"</code></p>
  
  <p>Where <code>fishnet</code> is a SpatialPolygonsDataFrame. Code subsets my SpPolDaFr so I get 15 subsetted SpPolDaFr written in the list. </p>
  
  <p>I was thinking of maybe being <code>foreach</code> the reason. However, I have other <code>foreach</code> calls a priori which run fine. I do the <code>doParallel</code> loop because my SpPolDaFr is 11 GB in size to speed things up. </p>