Skip to content

Commit

Permalink
Fix issue for fd_fric_intersect()
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Grenié committed Dec 2, 2023
1 parent 7eee0f4 commit 32bca4a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions R/fd_fric_intersect.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#' * `FRic_intersect` the volume of the convex hulls intersection of each
#' pair of site.
#'
#' ```{r child = "man/rmdchunks/no_row_names.Rmd"}
#' ```
#'
#' NB: FRic_intersect is equal to `NA` when there are strictly less species in
#' one of the sites than the number of provided traits. Note that only species
#' with strictly different trait combinations are considered unique, species
Expand Down Expand Up @@ -73,6 +76,12 @@ fd_fric_intersect <- function(traits, sp_com, stand = FALSE) {

}

if (is.null(rownames(sp_com))) {

rownames(sp_com) <- paste0("s", seq_len(nrow(sp_com)))

}

max_range <- 1

if (stand) {
Expand Down
3 changes: 3 additions & 0 deletions man/fd_fric_intersect.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/testthat/test-fric_intersect.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,23 @@ test_that("Functional Richness Inters. works on data.frame as well as matrix", {
)
})

test_that("Functional Richness Intersection works when sites have no names", {

site_sp_no_names <- site_sp_birds[1,, drop = FALSE]
rownames(site_sp_no_names) <- NULL

fric_int <- expect_silent(fd_fric_intersect(traits_birds, site_sp_no_names))

expect_s3_class(fric_int, "data.frame")
expect_identical(dim(fric_int), c(1L, 3L))
expect_named(fric_int, c("first_site", "second_site", "FRic_intersect"))

expect_equal(fric_int$FRic_intersect, 171543.73, tolerance = 1e-7)
expect_equal(fric_int[1, "first_site"], "s1")
expect_equal(fric_int[1, "second_site"], "s1")

})

# Tests for invalid inputs -----------------------------------------------------

test_that("Functional Richness Intersection fails gracefully", {
Expand Down

0 comments on commit 32bca4a

Please sign in to comment.