title: Error in dplyr group_by function, object not found
body: <p>I am asking this question because, as someone new to R, I am curious to why a piece of code I wrote works fine, and then the same line of code produces an error the next time it is run.</p>
  
  <p>Here is an example of a table I am working with.</p>
  
  <p>Dput: </p>
  
  <pre><code>structure(list(a5species = structure(c(4L, 1L, 6L, 3L, 14L, 3L, 
  8L, 8L, 8L, 8L, 8L, 8L, 3L, 4L, 4L, 8L, 4L, 4L, 4L, 4L, 4L, 4L, 
  4L, 4L, 8L, 8L, 8L, 8L, 8L, 8L, 4L, 8L, 8L, 8L, 3L, 8L, 8L, 8L, 
  12L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
  8L, 8L, 8L, 8L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 3L, 4L, 3L, 6L, 
  3L, 4L, 4L, 3L, 3L, 6L, 6L, 3L, 3L, 3L, 3L, 3L, 3L, 6L, 3L, 4L, 
  4L, 4L, 4L, 4L, 4L, 4L, 8L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
  3L, 3L, 1L, 4L, 3L, 3L, 3L, 4L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 3L, 
  4L, 8L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
  4L, 4L, 3L, 12L, 12L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 13L, 4L, 4L, 4L, 6L, 4L, 3L, 
  12L, 14L, 6L, 3L, 3L, 4L, 4L, 10L, 4L, 3L, 3L, 3L, 3L, 10L, 4L, 
  4L, 4L, 4L, 12L, 4L, 4L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
  4L, 4L, 4L, 4L, 4L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 
  4L, 4L, 4L, 4L, 6L, 5L, 4L, 10L, 12L, 4L, 4L, 3L, 6L, 4L, 3L, 
  4L), .Label = c("coustani", "demeilloni", "funestus", "gambiae", 
  "garnhami", "indetermine", "marshallii", "pharoensis", "pretoriensis", 
  "rufipes", "salbaii", "squamosus", "tenebrosus", "ziemani"), class = "factor"), 
      Vila = c("Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", "Motaze", 
      "Motaze", "Motaze", "Motaze", "Chicutso", "Chicutso", "Chicutso", 
      "Chicutso", "Chicutso", "Chicutso", "Chicutso", "Chicutso", 
      "Chicutso", "Chicutso", "Chicutso", "Chicutso", "Chicutso", 
      "Chicutso", "Chicutso", "Chicutso", "Chicutso", "Chicutso", 
      "Chicutso", "Chicutso", "Chicutso", "Chicutso", "Chicutso", 
      "Chicutso", "Chicutso", "Chicutso", "Chicutso", "Chicutso", 
      "Chicutso", "Chicutso", "Chicutso", "Chicutso", "Chicutso", 
      "Chicutso", "Chicutso", "Chicutso", "Chicutso", "Chicutso", 
      "Chicutso", "Chicutso", "Chicutso", "Chicutso", "Chicutso", 
      "Chicutso", "Chicutso", "Chicutso", "Chicutso", "Chicutso", 
      "Chicutso", "Chicutso", "Chicutso", "Chicutso", "Chicutso", 
      "Chicutso", "Chicutso", "Chicutso", "Chicutso", "Chicutso", 
      "Chicutso", "Chicutso", "Chicutso", "Chicutso", "Chicutso", 
      "Chicutso", "Chicutso", "Panjane", "Panjane", "Panjane", 
      "Panjane", "Panjane", "Panjane", "Panjane", "Panjane", "Panjane", 
      "Panjane", "Panjane", "Panjane", "Panjane", "Panjane", "Magude", 
      "Magude", "Magude", "Magude", "Magude", "Magude", "Magude", 
      "Magude", "Magude", "Magude", "Magude", "Magude", "Magude", 
      "Magude", NA, NA, "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", NA, NA, "Muginge", 
      "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", "Muginge", 
      "Muginge", "Muginge", "Muginge", "Mapulanguene", "Mapulanguene", 
      "Mapulanguene", "Mapulanguene", "Mapulanguene", "Mapulanguene", 
      "Mapulanguene", "Mapulanguene", "Mapulanguene", "Mapulanguene", 
      "Mapulanguene", "Mapulanguene")), class = c("tbl_df", "tbl", 
  "data.frame"), row.names = c(NA, -321L), .Names = c("a5species", 
  "Vila"))
  </code></pre>
  
  <p>And I used this code to organise the species by Vila: </p>
  
  <pre><code>test %&gt;% + group_by(Vila) %&gt;% filter(a5species=="gambiae") %&gt;%  + summarise(n=n())
  </code></pre>
  
  <p>Using this code produced the table I want, but the next time I tried to run the code it stopped working and produces the error:</p>
  
  <pre><code>Error in group_by_(.data, .dots = lazyeval::lazy_dots(...), add = add) : 
    object 'Vila' not found
  </code></pre>
  
  <p>I realise this is similar to the question posted here:
  <a href="https://stackoverflow.com/questions/27773881/r-object-not-found-if-defined-within-a-function-when-using-data-table-dplyr">R object not found if defined within a function when using data.table dplyr</a></p>
  
  <p>But I am using dplyr_0.4.3 and this question suggests that the problem they were experiencing would have been fixed by now, and also my code did work at one point. Further more, the discussion on this post is quite technical and it goes over my head. </p>
  
  <p>Any idea why my code suddenly stopped working?</p>
  
  <p>Thank you. </p>