2

I am trying to create a count of as a first step to calculate a percent cover for each category. The code below has worked before, but is no longer working.

I have read other posts on SO and none of them seem to capture the problem I'm experiencing.

Here is a reproducible example of what I'm trying to do:

 library(dplyr)

cover_data_test<- data.frame( site=c('cram','khq','k50'), 
                     treatment=c('exc','out','exc'), 
                     season=c('fall','spring','fall'),
                     transect=c(1,1,1), 
                     point=c(1,2,3),
                     ground=c('b','l','pb')
                     )
 View(cover_data_test)

  groundcover_test<- cover_data_test%>%
        group_by(season,site,treatment,transect)%>%
        count(ground)

I am still getting this error with the above example:

"Error in FUN(X[[i]], ...) : object 'b' not found"

Any ideas about what might be going on?

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Ashlee Simpson
  • 141
  • 1
  • 6
  • Just use `dput` or `head` to copy paste your data – Jason Mathews Jun 19 '19 at 21:25
  • 2
    It doesn't seem like that particular error message would come from that code. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jun 19 '19 at 21:27
  • Another thing to try is the classic computer hack. Restart R and/or RStudio. – Tony Ladson Jun 19 '19 at 21:29
  • 1
    I added a reproducible example that is giving me the same error. – Ashlee Simpson Jun 19 '19 at 21:41
  • I cannot replicate your error. If I copy/paste that code into R, it runs without error. Maybe you've reassigned something over a built in variable. You can check by running `conflicts()`. – MrFlick Jun 19 '19 at 21:42
  • I have tried restarting R and my computer and updating with the newest version. Thanks for your help! – Ashlee Simpson Jun 19 '19 at 21:42
  • Would you add output of `sessionInfo()` to your question? – M-- Jun 19 '19 at 21:56
  • 1
    @MrFlick The `conflicts()` function helped me get to the bottom of it! "count" was listed as a conflict so I edited the code to be `groundcover_test<- cover_data_test%>% group_by(season,site,treatment,transect)%>% dplyr::count(ground)` Adding the double colon operator allowed it to run as expected. Thanks again! – Ashlee Simpson Jun 19 '19 at 22:01

1 Answers1

12

The conflicts() function helped me get to the bottom of it! "count" was listed as a conflict so I edited the code to be r groundcover_test<- cover_data_test %>% group_by(season,site,treatment,transect)%>% dplyr::count(ground)

Adding the double colon operator dplyr:: allowed it to run as expected. Thanks again!

Ashlee Simpson
  • 141
  • 1
  • 6