From 9cf6ef5a297cad467e8fdfe53d70affa4be38502 Mon Sep 17 00:00:00 2001 From: Ethan White Date: Sat, 27 Jul 2024 18:44:31 -0400 Subject: [PATCH] Fix max counts for level=subregion 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. --- R/max_counts.R | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/R/max_counts.R b/R/max_counts.R index eb2b946..74fd62a 100644 --- a/R/max_counts.R +++ b/R/max_counts.R @@ -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") {