Skip to content

Commit

Permalink
fix to no c score in transect summary
Browse files Browse the repository at this point in the history
  • Loading branch information
ifoxfoot committed Sep 25, 2023
1 parent bbe306b commit eb1f799
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
6 changes: 4 additions & 2 deletions R/cover_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion R/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
47 changes: 46 additions & 1 deletion tests/testthat/test-cover_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit eb1f799

Please sign in to comment.