-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working on fixing functions using GNR
- Loading branch information
Zachary Foster
committed
Oct 23, 2024
1 parent
78d0d72
commit 5d2b66c
Showing
43 changed files
with
75,585 additions
and
505 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,45 @@ | ||
#' Parse scientific names using EOL's name parser. | ||
#' | ||
#' THIS FUNCTION IS DEFUNCT. | ||
#' | ||
#' @export | ||
#' @param names A vector of length 1 or more of taxonomic names | ||
#' @param ... Curl options passed on to [crul::verb-GET] | ||
#' @return A data.frame with results, the submitted names, and the | ||
#' parsed names with additional information. | ||
#' @seealso [gbif_parse()], [gn_parse()] | ||
#' @references http://gni.globalnames.org/ | ||
#' @examples \dontrun{ | ||
#' gni_parse("Cyanistes caeruleus") | ||
#' gni_parse("Plantago minor") | ||
#' gni_parse("Plantago minor minor") | ||
#' gni_parse(c("Plantago minor minor","Helianthus annuus texanus")) | ||
#' | ||
#' # pass on curl options | ||
#' gni_parse("Cyanistes caeruleus", verbose = TRUE) | ||
#' } | ||
#' @keywords internal | ||
gni_parse <- function(names, ...) { | ||
names <- paste0(names, collapse = "|") | ||
cli <- crul::HttpClient$new(paste0(gni_base(), "parsers.json"), | ||
headers = tx_ual, opts = list(...)) | ||
tt <- cli$get(query = list(names = names)) | ||
tt$raise_for_status() | ||
out <- jsonlite::fromJSON(tt$parse("UTF-8"), FALSE) | ||
dt2df(lapply(out, gni_parser), idcol = FALSE) | ||
.Defunct("ncbi_searcher", "traits", | ||
msg = "This function is defunct. See gn_parse()") | ||
# names <- paste0(names, collapse = "|") | ||
# url <- paste0("https://parser.globalnames.org/api/v1/", names) | ||
# cli <- crul::HttpClient$new(url, headers = tx_ual, opts = list(...)) | ||
# tt <- cli$get(query = list(cultivars = cultivars, csv = TRUE)) | ||
# tt$raise_for_status() | ||
# out <- jsonlite::fromJSON(tt$parse("UTF-8"), FALSE) | ||
# dt2df(lapply(out, gni_parser), idcol = FALSE) | ||
} | ||
|
||
gni_parser <- function(x) { | ||
positions_names <- vapply(x$scientificName$positions, function(y) | ||
paste("position_", y[[1]], sep = ""), "", USE.NAMES = FALSE) | ||
nums <- vapply(x$scientificName$positions, function(y) y[[2]], 1, | ||
USE.NAMES = FALSE) | ||
pv <- data.frame(as.list(setNames(nums, positions_names)), | ||
stringsAsFactors = FALSE) | ||
|
||
nmz <- c("verbatim","canonical", "normalized","hybrid","parsed") | ||
singles <- data.frame(x$scientificName[names(x$scientificName) %in% nmz], | ||
stringsAsFactors = FALSE) | ||
|
||
details2 <- data.frame() | ||
if (x$scientificName$parsed) { | ||
details_ <- x$scientificName$details[[1]] | ||
details_ <- details_[!names(details_) %in% 'status'] | ||
details <- dt2df(Map(function(x, y) data.frame(y, x, | ||
stringsAsFactors = FALSE), details_, names(details_)), | ||
idcol = FALSE)[,-3] | ||
details2 <- as.data.frame(t(data.frame(details[,2]))) | ||
names(details2) <- details[,1] | ||
row.names(details2) <- NULL | ||
} | ||
|
||
data.frame(Filter(NROW, list(details2, singles, pv)), | ||
stringsAsFactors = FALSE) | ||
} | ||
# gni_parser <- function(x) { | ||
# positions_names <- vapply(x$scientificName$positions, function(y) | ||
# paste("position_", y[[1]], sep = ""), "", USE.NAMES = FALSE) | ||
# nums <- vapply(x$scientificName$positions, function(y) y[[2]], 1, | ||
# USE.NAMES = FALSE) | ||
# pv <- data.frame(as.list(setNames(nums, positions_names)), | ||
# stringsAsFactors = FALSE) | ||
# | ||
# nmz <- c("verbatim","canonical", "normalized","hybrid","parsed") | ||
# singles <- data.frame(x$scientificName[names(x$scientificName) %in% nmz], | ||
# stringsAsFactors = FALSE) | ||
# | ||
# details2 <- data.frame() | ||
# if (x$scientificName$parsed) { | ||
# details_ <- x$scientificName$details[[1]] | ||
# details_ <- details_[!names(details_) %in% 'status'] | ||
# details <- dt2df(Map(function(x, y) data.frame(y, x, | ||
# stringsAsFactors = FALSE), details_, names(details_)), | ||
# idcol = FALSE)[,-3] | ||
# details2 <- as.data.frame(t(data.frame(details[,2]))) | ||
# names(details2) <- details[,1] | ||
# row.names(details2) <- NULL | ||
# } | ||
# | ||
# data.frame(Filter(NROW, list(details2, singles, pv)), | ||
# stringsAsFactors = FALSE) | ||
# } |
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
Oops, something went wrong.