Skip to content

Commit

Permalink
Fix couple of issues with summarizing queried taxon presence in datel…
Browse files Browse the repository at this point in the history
…ife result: when cleaned names have spaces instead of underscores and when datelife_result is empty (no matches).
  • Loading branch information
LunaSare committed Jan 8, 2024
1 parent e09cbeb commit 7088c13
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ DONE:
- faster and more accurate way to get study ids and tree ids from opentree API on `get_opentree_chronograms()` that have branch lengths in Myrs, no relative time.
- update to chronogram database, now with 292 chronograms.
- `get_taxon_summary()` now manages case when `datelife_result` is empty; throws warning instead of criptic error.
- better `testthat` suite for `datelife_search()` inner functions.


# datelife v0.6.8
Expand Down
5 changes: 3 additions & 2 deletions R/datelife_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ get_taxon_summary <- function(datelife_result = NULL,
message("Taxon summary can not be generated.")
return(NA)
}
if (length(datelife_result == 0)) {
if (length(datelife_result) == 0) {
warning("'datelife_result' is empty (length == 0).")
message("Taxon summary can not be generated.")
return(NA)
Expand All @@ -42,7 +42,8 @@ get_taxon_summary <- function(datelife_result = NULL,
cleaned_names <- gsub(" ", "_", datelife_query$cleaned_names)
} else {
input <- attributes(datelife_result)$datelife_query
cleaned_names <- gsub(" ", "_", input$cleaned_names)
input$cleaned_names <- gsub(" ", "_", input$cleaned_names)
cleaned_names <- input$cleaned_names
}
} else {
message("'datelife_query' argument was not provided.")
Expand Down
47 changes: 31 additions & 16 deletions tests/testthat/test_main.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@

test_that("a known datelife_search run works as it should", {
datelife_query <- make_datelife_query(input = c("Delphinus_delphis",
"Gallus gallus",
"elephas Maximus",
"felis_catus",
"homo-sapiens"))
expect_no_error(
datelife_query <- make_datelife_query(
input = c("Delphinus_delphis",
"Gallus gallus",
"elephas Maximus",
"felis_catus",
"homo-sapiens"))
)

datelifeSearch <- datelife_search(datelife_query,
summary_format = "phylo_median")

datelife_result <- get_datelife_result_datelifequery(
datelife_query = datelife_query,
partial = TRUE,
cache = "opentree_chronograms")
expect_no_error(
datelife_result <- get_datelife_result_datelifequery(
datelife_query = datelife_query,
partial = TRUE,
cache = "opentree_chronograms")
)

expect_true(length(datelife_result) > 0)

res <- summarize_datelife_result(
expect_no_error(
res <- summarize_datelife_result(
datelife_result = datelife_result,
datelife_query = datelife_query,
summary_format = "phylo_median",
na_rm = FALSE,
summary_print = c("citations", "taxa"),
taxon_summary = c("none", "summary", "matrix"),
criterion = "taxa")
)

taxon_summ <- get_taxon_summary(
expect_no_error(
taxon_summ <- get_taxon_summary(
datelife_result = datelife_result,
datelife_query = datelife_query)
)

expect_no_error(
datelifeSearch <- datelife_search(
datelife_query,
summary_format = "phylo_median")
)
})

##########################################
test_that("datelife_use workflows work", {
du <- datelife_use(
input = "Rhea americana, Struthio camelus, Gallus gallus",
Expand Down Expand Up @@ -78,6 +91,7 @@ test_that("datelife_use workflows work", {
input_process(input = du0)
})

#############################################################################
test_that("input processing a newick string and multiPhylo workflows work", {
newick <- "(Gallus_gallus,(Rhea_americana,Struthio_camelus)Palaeognathae)Aves;"
phylo <- input_process(newick)
Expand All @@ -94,16 +108,17 @@ test_that("input processing a newick string and multiPhylo workflows work", {
expect_warning(match_all_calibrations(phy = phylo, calibrations = calibs))
})

#################################
test_that("object checks work", {
expect_warning(match_all_calibrations(phy = NULL))
expect_error(use_calibrations(phy = NULL))
expect_error(get_calibrations_datelifequery(datelife_query = NULL))
})


###############################################
test_that("you can load opentree_chronograms",{
data(opentree_chronograms, package = "datelife")
expect_equal(ls(opentree_chronograms), c("authors","curators","dois","studies","trees"))
expect_true(all(c("authors","curators","dois","studies","trees") %in% ls(opentree_chronograms)))
})


Expand Down

0 comments on commit 7088c13

Please sign in to comment.