trashbirdecology / bbsAssistant

An R package for downloading and handling data and information from the North American Breeding Bird Survey.
Creative Commons Zero v1.0 Universal
27 stars 13 forks source link

QualityControlID not filtered correctly #120

Open see24 opened 1 year ago

see24 commented 1 year ago

When QualityControlID = 1 in munge_bbs_data, which is the default, I am still getting results with 0 in the QualityControlID column.

I checked the code and the issue is that the argument and column have the same name and inside the dplyr filter function it looks first in the context of the data frame so it does not use the value of QualityControlID = 1 that was supplied as an argument but rather the column in the data frame.

I will attempt to make a pull request now since it is an easy fix!

library(bbsAssistant)
library(dplyr)

# Set parameters for script
start_yr <- 1991
end_yr <- 2023

# Get the BBS data
# downloads the data the first time and will import it if already downloaded.
bbs_raw <- grab_bbs_data()

obs_ON_1991 <- munge_bbs_data(
  bbs_raw,
  states = region_codes %>% filter(State == "ontario") %>% pull(StateNum),
  zero.fill = FALSE,
  year.range = start_yr:end_yr,
  keep.stop.level.data = TRUE
)