-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add function is_in_tree (workaround #31)
- Loading branch information
1 parent
3d3e347
commit 064c44e
Showing
5 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
##' Some valid taxonomic names do not occur in the Synthetic | ||
##' Tree. This convenience function allows you to check whether a | ||
##' given Open Tree Taxonomy identifier (OTT id) is in the tree. A taxonomic | ||
##' name may not occur in the synthetic tree because (1) it is an | ||
##' extinct or invalid taxon, or (2) it is part of a group that is not | ||
##' monophyletic in the tree. | ||
##' | ||
##' @title Check that OTT ids occur in the Synthetic Tree | ||
##' @param ott_ids a vector of Open Tree Taxonomy identifiers | ||
##' @param ... additional arguments to customize the API request (see | ||
##' \code{\link{rotl}} package documentation). | ||
##' @return A named logical vector. \code{TRUE} indicates that the OTT | ||
##' id is in the synthetic tree, and \code{FALSE} that it is not. | ||
##' @examples | ||
##' \dontrun{ | ||
##' plant_families <- c("Asteraceae", "Solanaceae", "Poaceae", "Amaranthaceae", | ||
##' "Zamiaceae", "Araceae", "Juncaceae") | ||
##' matched_names <- tnrs_match_names(plant_families) | ||
##' ## This fails because some ott ids are not in the tree | ||
##' ## plant_tree <- tol_induced_subtree(ott_id(matched_names)) | ||
##' ## So let's check which ones are actually in the tree first: | ||
##' in_tree <- is_in_tree(ott_id(matched_names)) | ||
##' ## This now works: | ||
##' plant_tree <- tol_induced_subtree(ott_id(matched_names)[in_tree]) | ||
##' } | ||
##' | ||
##' @export | ||
is_in_tree <- function(ott_ids, ...) UseMethod("is_in_tree") | ||
|
||
|
||
##' @export | ||
is_in_tree.otl_ott_id <- function(ott_ids, ...) { | ||
|
||
in_tree <- vapply(ott_ids, function(ottid) { | ||
test <- try(tol_node_info(ottid, ...), silent = TRUE) | ||
if (inherits(test, "try-error")) { | ||
if (grepl("not find any synthetic tree nodes corresponding to the OTT id provided", test) && | ||
grepl(paste0("(", ottid, ")"), test)) { | ||
} else { | ||
warning("something seems off, check your internet connection?") | ||
} | ||
return(FALSE) | ||
} else { | ||
ott_id(test)[[1]] == ottid | ||
} | ||
|
||
}, logical(1), USE.NAMES = TRUE) | ||
|
||
in_tree | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters