Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locations with 0 birds being dropped in wt_replace_tmtt and wt_make_wide #46

Open
see24 opened this issue Jan 31, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@see24
Copy link
Contributor

see24 commented Jan 31, 2024

wt_replace_tmtt and wt_make_wide are removing sites with 0 birds despite calling wt_tidy_species with zerofill = TRUE

library(wildRtrax)

library(testthat)
library(dplyr)

# Download report to use for testing
Sys.setenv(WT_USERNAME = "guest", WT_PASSWORD = "Apple123")
wt_auth(force = TRUE)
#> Authentication into WildTrax successful.
ecosys21 <- wt_download_report(685, 'ARU', 'main', FALSE)

# add a location with 0 birds observed
ecosys21_mod_row <- slice(ecosys21, 1)
ecosys21_mod_row$species_code <- "MOBA"
ecosys21_mod_row$species_scientific_name <- NA
ecosys21_mod_row$vocalization <- "Non-vocal"
ecosys21_mod_row$location_id <- ecosys21_mod_row$location_id+max(ecosys21$location_id)
ecosys21_mod <- bind_rows(ecosys21, ecosys21_mod_row)

# all locations from input should be present in outputs unless not transcribed
ecosys21_locs <- ecosys21_mod %>% filter(aru_task_status == "Transcribed") %>%
  distinct(location_id)

ecosys21_tidy <- wt_tidy_species(ecosys21_mod, remove = c("mammals", "abiotic", "amphibians"), zerofill = T, "ARU")
#> Successfully downloaded the species table!
ecosys21_locs %>% anti_join(ecosys21_tidy, by = "location_id") %>%
  pull(location_id) %>%
  expect_length(0)

ecosys21_tmtt <- wt_replace_tmtt(ecosys21_tidy, calc = "round")
ecosys21_locs %>% anti_join(ecosys21_tmtt, by = "location_id") %>%
  pull(location_id) %>%
  expect_length(0)
#> Error: `.` has length 1, not length 0.

ecosys21_wide <- wt_make_wide(ecosys21_tmtt, sound = "all", sensor = 'ARU')
ecosys21_locs %>% anti_join(ecosys21_wide, by = "location_id") %>%
  pull(location_id) %>%
  expect_length(0)
#> Error: `.` has length 1, not length 0.

# total abundance should be 0
filter(ecosys21_wide, location_id == ecosys21_mod_row$location_id) %>%
  rowwise() %>%
  mutate(tot_birds = sum(c_across(matches("^....$")))) %>%
  pull(tot_birds) %>%
  expect_equal(0)
#> Error: `.` not equal to 0.
#> Lengths differ: 0 is not 1

Created on 2024-01-31 with reprex v2.0.2

@see24
Copy link
Contributor Author

see24 commented Jan 31, 2024

The code above will only run on my branch due to an issue with wt_tidy_species

see24 added a commit to see24/wildRtrax that referenced this issue Jan 31, 2024
needed to keep other columns from none to avoid them being filtered out later
alexmacphail added a commit that referenced this issue May 31, 2024
@alexmacphail alexmacphail added the bug Something isn't working label Aug 29, 2024
alexmacphail pushed a commit that referenced this issue Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants