diff --git a/R/cover_metrics.R b/R/cover_metrics.R index c1059f4..6b02d89 100644 --- a/R/cover_metrics.R +++ b/R/cover_metrics.R @@ -156,14 +156,16 @@ transect_summary <- function(x, key = "name", db, cover_class = "percent_cover", entries_c <- entries %>% dplyr::group_by(!!as.name(key)) %>% dplyr::mutate(mean = mean(.data$cover)) %>% - dplyr::distinct(!!as.name(key), mean, c) + dplyr::distinct(!!as.name(key), mean, c) %>% + dplyr::filter(!is.na(c)) #get native entries c entries_n <- entries %>% dplyr::filter(.data$nativity == "native") %>% dplyr::group_by(!!as.name(key)) %>% dplyr::mutate(mean = mean(.data$cover)) %>% - dplyr::distinct(!!as.name(key), mean, c) + dplyr::distinct(!!as.name(key), mean, c) %>% + dplyr::filter(!is.na(c)) #create list of all metrics that will be included in the output diff --git a/R/helper.R b/R/helper.R index f84d68c..ef340a7 100644 --- a/R/helper.R +++ b/R/helper.R @@ -31,7 +31,8 @@ transect <- data.frame(acronym = c("ABEESC", "ABIBAL", "AMMBRE", "ANTELE", "ABE cover = c(50, 4, 20, 30, 40, 7, 60), quad_id = c(1, 1, 1, 1, 2, 2, 2)) #na C Value -no_c_test <- data.frame(name = c("ABRONIA FRAGRANS", "ACER GLABRUM", "ACER GRANDIDENTATUM", "BOOP", "ACER PLATANOIDES")) +no_c_test <- data.frame(name = c("ABRONIA FRAGRANS", "ACER GLABRUM", "ACER GRANDIDENTATUM", "BOOP", "ACER PLATANOIDES"), + cover = c(1, 2, 3, 4, 62)) #cover method test cover_test <- data.frame(acronym = c("ABEESC", "ABIBAL", "AMMBRE", "ANTELE"), diff --git a/tests/testthat/test-cover_metrics.R b/tests/testthat/test-cover_metrics.R index bd8f5b9..dfd0bd5 100644 --- a/tests/testthat/test-cover_metrics.R +++ b/tests/testthat/test-cover_metrics.R @@ -114,7 +114,6 @@ test_that("transect_summary() works in with synonyms (diff names, same ID)", { ))) }) - test_that("transect_summary() works in with duplicates", { expect_equal(transect_summary(accepted_dup, "acronym", "michigan_2014"), @@ -161,6 +160,52 @@ test_that("transect_summary() works in with duplicates", { ))) }) +test_that("transect_summary() works in with no c score", { + expect_equal(transect_summary(no_c_test, "name", "montana_2017"), + + data.frame(metrics = c("Total Species Richness", + "Native Species Richness", + "Introduced Species Richness", + "% of Species with no C Value", + "% of Species with 0 C Value", + "% of Species with 1-3 C Value", + "% of Species with 4-6 C Value", + "% of Species with 7-10 C Value", + "Mean C", + "Native Mean C", + "Cover-Weighted Mean C", + "Cover-Weighted Native Mean C", + "Total FQI", + "Native FQI", + "Cover-Weighted FQI", + "Cover-Weighted Native FQI", + "Adjusted FQI", + "Mean Wetness", + "Native Mean Wetness", + "% Hydrophytes"), + values = c(species_richness(no_c_test, "name", "montana_2017", allow_no_c = T), + species_richness(no_c_test, "name", "montana_2017", native = TRUE, allow_no_c = T), + 1, #introduced + 50.00, #no c score + 0.0, #0 score + 25.0, #1-3 score + 25.0, #4-6 score + 0, #7-10 score + mean_c(no_c_test, "name", "montana_2017"), + mean_c(no_c_test, "name", "montana_2017", native = TRUE), + cover_mean_c(no_c_test, "name", "montana_2017", allow_duplicates = T), + cover_mean_c(no_c_test, "name", "montana_2017", native = TRUE, allow_duplicates = T), + FQI(no_c_test, "name", "montana_2017"), + FQI(no_c_test, "name", "montana_2017", native = TRUE), + cover_FQI(no_c_test, "name", "montana_2017", allow_duplicates = T), + cover_FQI(no_c_test, "name", "montana_2017", allow_duplicates = T, native = TRUE), + adjusted_FQI(no_c_test, "name", "montana_2017"), + mean_w(no_c_test, "name", "montana_2017", allow_no_c = T), + mean_w(no_c_test, "name", "montana_2017", native = TRUE, allow_no_c = T), + NA #hydro + ))) +}) + #------------------------------------------------------------------------------- #testing plot_summary()