From 1398a4f159f803b366be48668ed17870311f11fd Mon Sep 17 00:00:00 2001 From: Mattia Ghilardi Date: Thu, 29 Feb 2024 11:32:12 +0100 Subject: [PATCH] Fixed species_family to return latest db version --- DESCRIPTION | 60 ++++++++++++++++++++++++++++------------------ NAMESPACE | 1 + R/species_family.R | 26 ++++++++++++++++++-- 3 files changed, 62 insertions(+), 25 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d98197b..510b9dd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,35 +1,49 @@ -Package: rFishTaxa Type: Package +Package: rFishTaxa Title: R Interface to 'Eschmeyer's Catalog of Fishes' Version: 0.1.0 Date: 2022-09-08 -Authors@R: c(person(given = "Liuyong", family = "Ding", email = "ly_ding@126.com", role = c("aut", "cre"), comment = c(ORCID="0000-0002-5490-182X")), - person(given = "Zhixin", family = "Zhang", email = "zhangzhixin1102@hotmail.com", role = "ctb") - ) +Authors@R: + c(person(given = "Liuyong", + family = "Ding", + role = c("aut", "cre"), + email = "ly_ding@126.com", + comment = c(ORCID = "0000-0002-5490-182X")), + person(given = "Zhixin", + family = "Zhang", + role = "ctb", + email = "zhangzhixin1102@hotmail.com")) Maintainer: Liuyong Ding -Description: `Eschmeyer's Catalog of Fishes` is the authoritative reference for taxonomic fish names, featuring a searchable online database. This package helps users to query valid taxonomic fish information for biodiversity estimates, conservation issues, etc. -Depends: R (>= 4.0.0) +Description: `Eschmeyer's Catalog of Fishes` + is + the authoritative reference for taxonomic fish names, featuring a + searchable online database. This package helps users to query valid + taxonomic fish information for biodiversity estimates, conservation + issues, etc. +License: Artistic-2.0 +URL: https://otoliths.github.io/rFishTaxa/ +BugReports: https://github.com/Otoliths/rFishTaxa/issues +Depends: + R (>= 4.0.0) Imports: - httr, - tibble, - magrittr, - xml2, - dplyr, - stringr, - rvest, - janitor + dplyr, + httr, + janitor, + magrittr, + rvest, + stringr, + tibble, + tidyr, + xml2 Suggests: - utils, - testthat, - rmarkdown, + devtools, knitr, prettydoc, - devtools + rmarkdown, + testthat, + utils VignetteBuilder: - knitr, + knitr, rmarkdown -License: Artistic-2.0 -URL: https://otoliths.github.io/rFishTaxa/ -BugReports: https://github.com/Otoliths/rFishTaxa/issues Encoding: UTF-8 -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.3 diff --git a/NAMESPACE b/NAMESPACE index d8a83d1..e9a6e3c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,6 +18,7 @@ importFrom(stringr,str_sub) importFrom(stringr,str_trim) importFrom(tibble,as_tibble) importFrom(tibble,enframe) +importFrom(tidyr,fill) importFrom(utils,browseURL) importFrom(xml2,read_html) importFrom(xml2,xml_find_all) diff --git a/R/species_family.R b/R/species_family.R index 0c1c89b..6b11a22 100644 --- a/R/species_family.R +++ b/R/species_family.R @@ -26,6 +26,8 @@ #' @importFrom utils browseURL #' @importFrom janitor clean_names #' @importFrom dplyr filter +#' @importFrom dplyr mutate +#' @importFrom tidyr fill #' @details See for website \url{https://researcharchive.calacademy.org/research/ichthyology/catalog/SpeciesByFamily.asp} details. #' @references \url{https://github.com/curso-r/lives/blob/6e042cf5f0bae0d957ff487a39b6601ac6f514ea/drafts/20210915_webscraping_ichthyology.R} #' @examples @@ -61,8 +63,28 @@ species_family <- function(){ rvest::html_table() %>% janitor::clean_names() %>% dplyr::filter(class != "Totals") - r <- readRDS(paste0(system.file("extdata",package = "rFishTaxa"),"/","db_2022_09.rds")) - return(tibble::as_tibble(r)) + result %>% + dplyr::mutate(order = ifelse(endsWith(order, "formes") | endsWith(order, "*"), + order, + NA), + class = ifelse(is.na(available_genera) & is.na(order), + class, + NA), + # "Percalates-clade" among families as of 6 February 2024 + family = ifelse(endsWith(family, "idae") | endsWith(family, '-clade"'), + family, + NA), + subfamily = ifelse(!is.na(available_genera) & is.na(family), + subfamily, + NA) + # subfamily = ifelse(endsWith(subfamily, "inae") | endsWith(subfamily, " sedis"), + # subfamily, + # NA) + ) %>% + tidyr::fill("class", "order", "family") %>% + dplyr::filter(!is.na(available_genera)) + # r <- readRDS(paste0(system.file("extdata",package = "rFishTaxa"),"/","db_2022_09.rds")) + # return(tibble::as_tibble(r)) }else{ cat("Error request - the parameter query is not valid") browseURL(url)