Error: n() should only be called in a data context

I keep getting this error whenever I run the following code:

library(dplyr, warn.conflicts = FALSE)

df8<-df6 %>%
mutate(DateTimeUTC = lubridate::mdy_hms(DateTimeUTC),
     gr = lag(cumsum(!UserIsEditing), default = TRUE)) %>%
slice(-c(1, n())) %>%
group_by(gr) %>%
summarise(Start = min(DateTimeUTC),
        End = max(DateTimeUTC),
        Duration = as.integer(End - Start), 
        RowNum = n(), 
        Length = ItemBodyLength[n()]) %>%
mutate(RowNum = cumsum(RowNum)) %>%
slice(n():1) %>%

I have a large dataset that resembles this: image

I have researched this and not sure why this error keeps coming up.
Any help or suggestion is appreciated.

Screenshots are not very useful, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.