Skip to content

Commit

Permalink
Fix max counts for level=subregion
Browse files Browse the repository at this point in the history
The use of .data was causing errors due to use of `$` when specifying single column
names not being allowed and likely further down the pipe as well. This removes use
of .data in the section of the code triggerd by level = "subregion".

It also fixes a problem caused by using bind_rows with different named columns
("region" in one table, "subregion" in another table).

The goal was to maintain the behavior of the function as written, but I think
there is also a conversation to be had about how level = "subregion" results in
data source mixing that may be unintuitive to users and should be clearly
documented.
  • Loading branch information
ethanwhite committed Jul 27, 2024
1 parent 62f8f60 commit 9cf6ef5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions R/max_counts.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ max_counts <- function(path = get_default_data_path(),
if(level == "subregion") {
colony_table <- load_datafile("SiteandMethods/colonies.csv") %>% dplyr::select(-c("latitude","longitude"))
out <- colonies %>%
dplyr::left_join(colony_table, by = dplyr::join_by(.data$group_id, .data$colony)) %>%
dplyr::group_by(.data$year, .data$subregion, .data$species) %>%
dplyr::summarise(count = sum(.data$count)) %>%
dplyr::filter(.data$subregion %in% c("2a","2b", "3an", "3as", "3ase", "3b")) %>%
dplyr::left_join(colony_table, by = dplyr::join_by(colony)) %>%
dplyr::group_by(year, subregion, species) %>%
dplyr::summarise(count = sum(count)) %>%
dplyr::filter(subregion %in% c("2a","2b", "3an", "3as", "3ase", "3b")) %>%
dplyr::rename(subregion, region = subregion) %>%
dplyr::bind_rows(regions) %>%
dplyr::filter(.data$region %in% c("1", "2a","2b", "3an", "3as", "3ase", "3b", "enp")) %>%
dplyr::filter(region %in% c("1", "2a","2b", "3an", "3as", "3ase", "3b", "enp")) %>%
dplyr::select("year", "region", "species", "count") %>%
dplyr::arrange(.data$region, .data$species, .data$year)
dplyr::arrange(region, species, year)
}

if(level == "region") {
Expand Down

0 comments on commit 9cf6ef5

Please sign in to comment.