Skip to content

Commit

Permalink
accommodate missing species. Closes #46.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhpob committed Dec 20, 2024
1 parent b83bf22 commit 17aa382
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: otndo
Title: Understand your OTN data
Version: 0.3.3
Version: 0.3.4
Authors@R:
person("Michael", "O'Brien", , "mike@obrien.page", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1420-6395"))
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## otndo 0.3
### v 0.3.4
* Fix bug introduced in v 0.3.0 where receiver match tables couldn't be created if the source network does not share species data. [Issue #46](https://github.com/mhpob/otndo/issues/46)

### v 0.3.3
* Fix bug where reports would be silently dropped if it matched a file name that already existed. [Issue #45](https://github.com/mhpob/otndo/issues/45)

Expand Down
7 changes: 6 additions & 1 deletion R/match_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ match_table <- function(
),
PI_emails = reactable::colDef(show = F),
POC_emails = reactable::colDef(show = F),
`Project name` = reactable::colDef(minWidth = 200)
`Project name` = reactable::colDef(minWidth = 200),
Species = reactable::colDef(show = !all(is.na(mt_data$Species)))
)
)
}
Expand All @@ -104,6 +105,10 @@ prep_match_table <- function(

extract <- data.table::data.table(extract)

if (isFALSE("scientificname" %in% names(extract))) {
extract[, scientificname := character()]
}

if (type == "tag") {
mt <- merge(
extract[, .(detections = .N), by = c("detectedby", "scientificname")],
Expand Down
1 change: 1 addition & 0 deletions otndo.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 17390ab4-b811-421c-b728-dee2ac2db051

RestoreWorkspace: No
SaveWorkspace: No
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-match_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,17 @@ test_that("creates a js table for tag data", {
)
)
})



test_that("species columnn is dropped if no species present", {
qual <- read.csv(pbsm$qualified)
qual$scientificname <- NULL

tbl_qual <- match_table(qual, "receiver")

expect_false(tbl_qual$x$tag$attribs$columns[[6]]$show)

expect_s3_class(tbl_qual, c("reactable", "htmlwidget"), exact = TRUE)
expect_type(tbl_qual$x, "list")
})
20 changes: 20 additions & 0 deletions tests/testthat/test-prep_match_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,23 @@ test_that("receiver project with multiple species is summarized", {
c(2, 1)
)
})


test_that("networks without species info (ACT) work", {
qual <- read.csv(pbsm$qualified)
qual$scientificname <- NULL

tbl_no_spp <- prep_match_table(qual, "receiver")

# Make sure the test was set up correctly
# No spp info means each project should be represented once.
expect_equal(
nrow(tbl_no_spp),
data.table::uniqueN(tbl_no_spp, by = "Project name")
)

expect_true(
all(is.na(tbl_no_spp$Species))
)

})

0 comments on commit 17aa382

Please sign in to comment.