diff --git a/DESCRIPTION b/DESCRIPTION index 7a0ffef..302611a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -6,7 +6,7 @@ Description: A programmatic interface to 'FishBase', re-written supports experimental access to 'SeaLifeBase' data, which contains nearly 200,000 species records for all types of aquatic life not covered by 'FishBase.' -Version: 4.1.1 +Version: 5.0.0 Encoding: UTF-8 License: CC0 Authors@R: c(person("Carl", "Boettiger", @@ -26,31 +26,20 @@ LazyData: true Depends: R (>= 4.0) Imports: - methods, - utils, - tools, - purrr, - progress, - memoise, - rlang, - magrittr, - readr (>= 2.0.0), + glue, stringr, + purrr, jsonlite, - DBI, dplyr, - dbplyr, - duckdb, - contentid (>= 0.0.15), - rstudioapi, - fs, - glue, - tibble + duckdbfs, + rlang, + magrittr, + memoise Suggests: testthat, rmarkdown, knitr, covr, spelling -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Language: en-US diff --git a/NAMESPACE b/NAMESPACE index ebcc841..e7cadd2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,22 +9,15 @@ export(common_to_sci) export(country) export(countrysub) export(countrysubref) -export(db_dir) -export(db_disconnect) export(diet) export(diet_items) -export(distribution) -export(docs) export(ecology) export(ecosystem) export(estimate) export(faoareas) -export(fb_conn) -export(fb_import) export(fb_tables) export(fb_tbl) export(fecundity) -export(fishbase_pane) export(fooditems) export(genetics) export(introductions) @@ -36,7 +29,6 @@ export(load_taxa) export(maturity) export(morphology) export(morphometrics) -export(occurrence) export(oxygen) export(popchar) export(popgrowth) @@ -52,17 +44,13 @@ export(sci_to_common) export(spawning) export(species) export(species_by_ecosystem) -export(species_list) -export(species_names) export(speed) export(stocks) export(swimming) export(synonyms) export(validate_names) -importFrom(dbplyr,translate_sql) importFrom(dplyr,collect) importFrom(dplyr,distinct) -importFrom(dplyr,enquo) importFrom(dplyr,filter) importFrom(dplyr,left_join) importFrom(dplyr,mutate) @@ -71,24 +59,9 @@ importFrom(dplyr,rename) importFrom(dplyr,right_join) importFrom(dplyr,select) importFrom(dplyr,sym) -importFrom(fs,dir_create) -importFrom(fs,dir_ls) -importFrom(fs,path) importFrom(magrittr,`%>%`) -importFrom(methods,as) -importFrom(methods,is) -importFrom(progress,progress_bar) -importFrom(purrr,map_chr) importFrom(purrr,map_dfr) -importFrom(readr,read_csv) importFrom(rlang,"!!") importFrom(rlang,.data) -importFrom(stats,na.omit) -importFrom(stringr,str_extract) importFrom(stringr,str_to_lower) -importFrom(tools,R_user_dir) -importFrom(utils,data) importFrom(utils,globalVariables) -importFrom(utils,lsf.str) -importFrom(utils,packageVersion) -importFrom(utils,read.csv) diff --git a/NEWS.md b/NEWS.md index 8454461..c9ef7bf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -23,10 +23,35 @@ And constructed with the following guidelines: For more information on SemVer, please visit http://semver.org/. +v 5.0.0 +------- + +Another streamlined re-design following new abilities for data hosting and access. +This release relies on a HuggingFace datasets hosting for data and metadata hosting +in parquet and schema.org. + +Data access is simplified to use the simple HuggingFace datasets API instead +of the previous contentid-based resolution. This allows metadata to be defined +with directly alongside the data platform independent of the R package. + +A simplified access protocol relies on `duckdbfs` for direct reads of tables. +Several functions previously used only to manage connections are now deprecated +or removed, along with a significant number of dependencies. + +Core use still centers around the same package API using the `fb_tbl()` function, +with legacy helper functions for common tables like `species()` are still accessible and +can still optionally filter by species name where appropriate. As before, loading the +full tables and sub-setting manually is still recommended. + +Historic helper functions like `load_taxa()` (combining the taxonomic classification from Species, +Genus, Family and Order tables), `validate_names()`, and `common_to_sci()` and +`sci_to_common()` should be in working order, all using table-based outputs. + + v 4.1.1 ------- -* hotfix for bug in 4.1.0 on Windows -- duckdb httpfs on windows creates sigfault +* hotfix for bug in 4.1.0 on Windows -- `duckdb` `httpfs` on windows created `segfault` v 4.1.0 -------- diff --git a/R/00-endpoint.R b/R/00-endpoint.R index 659c26f..4eec97f 100644 --- a/R/00-endpoint.R +++ b/R/00-endpoint.R @@ -1,7 +1,4 @@ -utils::globalVariables("sci_name", package="rfishbase") - - ## Allows us to define functions for each endpoint using closures #' @importFrom dplyr left_join rename sym #' @importFrom rlang !! .data @@ -9,68 +6,35 @@ endpoint <- function(endpt, join = NULL, by = NULL){ function(species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ...){ - out <- fb_tbl(endpt, server, version, db) %>% fix_ids() + out <- fb_tbl(endpt, server, version) %>% fix_ids() if(!is.null(species_list)){ species <- - dplyr::select(fb_tbl("species", server, version, db), - "SpecCode", "Genus", "Species") %>% + fb_tbl("species", server, version) %>% + dplyr::select("SpecCode", "Genus", "Species") %>% dplyr::mutate(sci_name = paste(Genus, Species)) %>% dplyr::filter(sci_name %in% species_list) %>% dplyr::select(Species=sci_name, "SpecCode") + out <- dplyr::inner_join(species, out) %>% dplyr::distinct() } - if(!is.null(fields)){ - out <- select(out, !!fields) %>% dplyr::distinct() + out <- dplyr::select(out, !!fields) %>% dplyr::distinct() } - if(!is.null(join)) - out <- left_join(out, join, by = by) - - dplyr::collect(out) - } - -} - - -species_subset <- function(species_list, - full_data, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db()){ - - - species <- - dplyr::select(dplyr::tbl(db, "species"), - "SpecCode", "Genus", "Species") %>% - dplyr::mutate(sci_name = paste(Genus, Species)) %>% - dplyr::select("SpecCode", Species=sci_name) %>% - collect() - - - - ## "Species" in many tables is just the epithet, we want full species name so drop that. - if("Species" %in% colnames(full_data)){ - sp <- dplyr::sym("Species") - full_data <- dplyr::select(full_data, - !!sp) - } - - if(is.null(species_list)){ - return(dplyr::left_join(species, full_data, by = "SpecCode")) + if(!is.null(join)) { + out <- dplyr::left_join(out, join, by = by) + } + out } - - speccodes(species_list, table = species, db = db) %>% - dplyr::left_join(full_data, by = "SpecCode") } - ## handle ids or species names, returning remote table for joining speccodes <- function(species_list, table, db){ if(is.integer(species_list)){ @@ -78,13 +42,7 @@ speccodes <- function(species_list, table, db){ } else { df <- dplyr::tibble(Species = species_list) } - - ## Manually copy. we want a left_join since right_join isn't in RSQLite - ## but left_join(copy=TRUE) would copy the larger table instead - #tmp <- tmp_tablename() - #dplyr::copy_to(db, df = df, name = tmp, overwrite=TRUE, temporary=TRUE) - #df <- dplyr::tbl(db, tmp) - + suppressMessages({ dplyr::left_join(df, table) %>% select("SpecCode", "Species") @@ -93,8 +51,6 @@ speccodes <- function(species_list, table, db){ - - #' @importFrom dplyr sym fix_ids <- function(full_data){ if("Speccode" %in% colnames(full_data)){ @@ -111,13 +67,22 @@ fix_ids <- function(full_data){ ## Define function that maps sci names to SpecCode, subsets table by requested sci name or spec code #' @importFrom dplyr mutate select fb_species <- function(server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + version = "latest", + db = NULL, ...){ - load_taxa(server, version, db, collect = FALSE, ...) %>% dplyr::select("SpecCode", "Species") + load_taxa(server, version, db=NULL, collect = FALSE, ...) %>% + dplyr::select("SpecCode", "Species") } tmp_tablename <- function(n=10) paste0("tmp_", paste0(sample(letters, n, replace = TRUE), collapse = "")) + + +utils::globalVariables("sci_name", package="rfishbase") + + +#' @importFrom magrittr `%>%` +#' @export +magrittr::`%>%` diff --git a/R/available_releases.R b/R/available_releases.R deleted file mode 100644 index ab6d6f8..0000000 --- a/R/available_releases.R +++ /dev/null @@ -1,49 +0,0 @@ - -#' List available releases -#' -#' @param server fishbase or sealifebase -#' @details Lists all available releases (year.month format). -#' To use a specific release, set the desired release using -#' `options(FISHBASE_VERSION=)`, as shown in the examples. -#' Otherwise, rfishbase will use the latest available version if this -#' option is unset. NOTE: it will be necessary -#' to clear the cache with `clear_cache()` or by restarting the R session -#' with a fresh environment. -#' @export -#' @examplesIf interactive() -#' available_releases() -#' options(FISHBASE_VERSION="19.04") -#' ## unset -#' options(FISHBASE_VERSION=NULL) -#' @importFrom stats na.omit -available_releases <- function(server = c("fishbase", "sealifebase")){ - prov <- read_prov(server) - - who <- names(prov) - if("@graph" %in% who){ - prov <- prov[["@graph"]] - } else { - prov <- list(prov) - } - - avail_versions <- map_chr(prov, "version", .default=NA) - as.character(sort(na.omit(avail_versions), TRUE)) - -} - -#' @importFrom purrr map_chr -#' @importFrom stringr str_extract -get_latest_release <- function(server = c("fishbase", "sealifebase")) { - available_releases(server)[[1]] -} - - -get_release <- function(){ - - version <- getOption("FISHBASE_VERSION") - if(is.null(version)) - version <- Sys.getenv("FISHBASE_VERSION") - if(version == "") - version <- get_latest_release() - version -} diff --git a/R/common_names.R b/R/common_names.R index 95ff20e..4404a86 100644 --- a/R/common_names.R +++ b/R/common_names.R @@ -15,22 +15,22 @@ #' common_to_sci(c("Bicolor cleaner wrasse", "humphead parrotfish"), Language="English") #' common_to_sci(c("Coho Salmon", "trout")) #' } -#' @seealso \code{\link{species_list}}, \code{\link{synonyms}} +#' @seealso \code{\link{synonyms}} #' @export #' @importFrom dplyr filter select distinct collect #' @importFrom stringr str_to_lower #' @importFrom purrr map_dfr common_to_sci <- function(x, Language = "English", - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db()){ + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL){ - comnames <- get_comnames(server, version, db) %>% dplyr::collect() + comnames <- get_comnames(server, version) subset <- purrr::map_dfr(x, function(y){ y <- stringr::str_to_lower(y) - y <- enquo(y) + y <- rlang::enquo(y) dplyr::filter(comnames, grepl(!!y, stringr::str_to_lower(ComName))) }) @@ -38,19 +38,20 @@ common_to_sci <- function(x, } -get_comnames <- function(server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(), - lang = "English"){ - ## FIXME switch to SLB if server indicates - df <- fb_tbl("comnames", server, version, db) +get_comnames <- function(server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, + lang = "English"){ + ## Many spec-codes may have multiple Common Names in a given language! + sp_names <- fb_species(server, version) + df <- fb_tbl("comnames", server, version) Language <- rlang::sym("Language") value <- rlang::quo(lang) comnames <- df %>% dplyr::select("ComName", "Language", "SpecCode") %>% dplyr::filter(!!Language == !!value) %>% dplyr::distinct() %>% - dplyr::left_join(fb_species(server, version, db), by = "SpecCode") %>% + dplyr::left_join(sp_names, by = "SpecCode") %>% dplyr::select("Species", "ComName", "Language", "SpecCode") comnames @@ -64,20 +65,22 @@ globalVariables(c("ComName", "Language")) #' @param Language a string specifying the language for the common name, e.g. "English" #' @return a data.frame of common names by species queried. If multiple species are queried, #' The resulting data.frames are concatenated. -#' @details Note that there are many common names for a given sci name, so sci_to_common doesn't make sense +#' @details Note that there are many common names for a given sci name #' #' @export common_names sci_to_common #' @aliases common_names sci_to_common +#' @examplesIf interactive() +#' common_names("Bolbometopon muricatum") +#' common_names <- function(species_list = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, Language = "English", fields = NULL){ - species_subset(species_list, - get_comnames(server, version, db, lang = Language), - server, version, db) %>% - dplyr::collect() + + get_comnames(server, version, db, lang = Language) |> + filter(Species %in% species_list) } diff --git a/R/cran-hacks.R b/R/cran-hacks.R deleted file mode 100644 index 8f1b37b..0000000 --- a/R/cran-hacks.R +++ /dev/null @@ -1,11 +0,0 @@ - -#' @importFrom progress progress_bar -#' @importFrom dbplyr translate_sql -dummy <- function(){ - # dbplyr is required for the database backend, but is only suggested by dplyr - # Consequently, functions use dplyr - x <- 2 - dbplyr::translate_sql(x + 1) - progress::progress_bar$new(total = 100) - NULL -} \ No newline at end of file diff --git a/R/distribution.R b/R/distribution.R index 2805d66..1621b2e 100644 --- a/R/distribution.R +++ b/R/distribution.R @@ -1,5 +1,6 @@ ## Consider information from: Countries | FAO areas | Ecosystems | Occurrences | Point map | Introductions | Faunaf +default_db <- function() NULL # avoid globals DateEntered <- NA @@ -17,10 +18,8 @@ Ecosystemname <- NA #' @export #' @examplesIf interactive() #' \dontrun{ -#' country(species_list(Genus='Labroides')) +#' country("Bolbometopon muricatum") #' } -#' @details -#' e.g. http://www.fishbase.us/Country country <- endpoint("country", join = country_names()) #' countrysub @@ -60,11 +59,7 @@ countrysubref <- function(server = getOption("FISHBASE_API", "fishbase"), #' @param c_code a C_Code or list of C_Codes (FishBase country code) #' @export #' @examplesIf interactive() -#' \dontrun{ #' c_code(440) -#' } -#' @details -#' e.g. http://www.fishbase.us/Country c_code <- function(c_code = NULL, server = getOption("FISHBASE_API", "fishbase"), version = get_latest_release(), @@ -84,29 +79,10 @@ c_code <- function(c_code = NULL, globalVariables(c("C_Code", "PAESE")) country_names <- function(server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db()){ - fb_tbl("countref", server, version, db) %>% select(country = PAESE, C_Code) -} -#' distribution -#' -#' return a table of species locations as reported in FishBASE.org FAO location data -#' -#' @inheritParams species -#' @export -#' @examplesIf interactive() -#' \dontrun{ -#' distribution(species_list(Genus='Labroides')) -#' } -#' @details currently this is ~ FAO areas table (minus "note" field) -#' e.g. http://www.fishbase.us/Country/FaoAreaList.php?ID=5537 -distribution <- function(species_list=NULL, - fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(), - ...){ - faoareas(species_list, fields = fields, server = server, version, db) + version = "latest", + db = NULL){ + fb_tbl("countref", server, version, db) %>% + select(country = PAESE, C_Code) } @@ -119,23 +95,17 @@ distribution <- function(species_list=NULL, #' @export #' @return a tibble, empty tibble if no results found #' @examplesIf interactive() -#' \dontrun{ #' faoareas() -#' } -#' @details currently this is ~ FAO areas table (minus "note" field) -#' e.g. http://www.fishbase.us/Country/FaoAreaList.php?ID=5537 faoareas <- function(species_list = NULL, fields = NULL, server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(), + version = "latest", + db = NULL, ...){ - area <- fb_tbl("faoareas", server, version, db) - ref <- faoarrefs(server, version, db) + area <- fb_tbl("faoareas", server, version) + ref <- faoarrefs(server, version) out <- left_join(area, ref, by = "AreaCode") out <- select_fields(out, fields) - - species_subset(species_list, out, server, version, db) %>% - dplyr::collect() + species_subset(species_list, out, server=server, version=version) } select_fields <- function(df, fields = NULL){ @@ -145,8 +115,8 @@ select_fields <- function(df, fields = NULL){ } faoarrefs <- function(server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db()){ + version = "latest", + db = NULL){ fb_tbl("faoarref", server, version, db) } @@ -167,11 +137,11 @@ faoarrefs <- function(server = getOption("FISHBASE_API", "fishbase"), ecosystem <- function(species_list = NULL, fields = NULL, server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(), + version = "latest", + db = NULL, ...){ endpt = "ecosystem" - join = fb_tbl("ecosystemref", server = server, version = version, db = db) + join = fb_tbl("ecosystemref", server = server, version = version) by = "E_CODE" full_data <- fb_tbl(endpt, server, version, db) %>% fix_ids() out <- species_subset(species_list, full_data, server, version, db) @@ -197,7 +167,7 @@ ecosystem <- function(species_list = NULL, #' } species_by_ecosystem <- function(ecosystem, species_list = NULL, server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), db = default_db(), ...) { + version = "latest", db = NULL, ...) { ecosysref = fb_tbl("ecosystemref", server, version, db) ecosysname <- dplyr::filter(ecosysref, EcosystemName == ecosystem) @@ -207,23 +177,21 @@ species_by_ecosystem <- function(ecosystem, species_list = NULL, e_code <- dplyr::collect(ecosysname)$E_CODE out <- dplyr::filter(ecosys, E_CODE == e_code) species <- dplyr::select(load_taxa(server, version, db, collect=FALSE), "SpecCode", "Species") - out <- left_join(out, species, by = "SpecCode") - out <- left_join(out, dplyr::select(ecosysref, E_CODE, EcosystemName), + out <- dplyr::left_join(out, species, by = "SpecCode") + out <- dplyr::left_join(out, dplyr::select(ecosysref, E_CODE, EcosystemName), by = "E_CODE") out <- dplyr::relocate(out, E_CODE, EcosystemName, SpecCode, Species) dplyr::collect(out) } -#' occurrence -#' -#' @details THE OCCURRENCE TABLE HAS BEEN DROPPED BY FISHBASE - THIS -#' FUNCTION NOW RETURNS A STOP MESSAGE. -#' @export -occurrence <- function() { - stop("occurrence is no longer available", call. = FALSE) - #endpoint("occurrence") +species_subset <- function(species_list, full_data, server, version, db=NULL) { + codes <- fb_species(server, version) |> + dplyr::filter(Species %in% species_list) + + full_data |> dplyr::inner_join(codes) } + #' introductions #' #' @return a table of species introductions data diff --git a/R/docs.R b/R/docs.R deleted file mode 100644 index caf678b..0000000 --- a/R/docs.R +++ /dev/null @@ -1,37 +0,0 @@ -#' docs -#' -#' documentation of tables and fields -#' @inheritParams species -#' @param table the table for which the documentation should be displayed. If no table is given, -#' documentation summarizing all available tables is shown. -#' @return A data.frame which lists the name of each table (if no table argument is given), along with a description -#' of the table and a URL linking to further information about the table. If a specific table is named in the -#' table argument, then the function will return a data.frame listing all the fields (columns) found in that table, -#' a description of what the field label means, and the units in which the field is measured. These descriptions of the -#' columns are not made available by FishBase and must be manually generated and curated by FishBase users. -#' At this time, many fields are still missing. Please take a moment to fill in any fields you use in the source -#' table here: https://github.com/ropensci/fishbaseapi/tree/master/docs/docs-sources -#' @importFrom utils read.csv -#' @examplesIf interactive() -#' \donttest{ -#' tables <- docs() -#' # Describe the fecundity table -#' dplyr::filter(tables, table == "fecundity")$description -#' ## See fields in fecundity table -#' docs("fecundity") -#' ## Note: only -#' } -#' @export -docs <- function(table = NULL, server = NULL, ...){ - - suppressMessages({ - if(is.null(table)){ - return(read.csv(system.file(file.path("extdata","tables.csv"), - package="rfishbase"))) - } - read.csv(system.file(file.path("extdata", paste0(table, ".csv")), - package="rfishbase"), - stringsAsFactors = FALSE) - }) -} - diff --git a/R/duckdb-direct.R b/R/duckdb-direct.R deleted file mode 100644 index 6296455..0000000 --- a/R/duckdb-direct.R +++ /dev/null @@ -1,46 +0,0 @@ - - -# -duckdb_import <- function(urls, - tablenames = basename(urls), - conn = fb_conn(), - local = getOption("rfishbase_local_db", FALSE)) { - - - #DBI::dbExecute(conn, "INSTALL 'httpfs';") # import from HTTP - #DBI::dbExecute(conn, "LOAD 'httpfs';") - - current_tbls <- DBI::dbListTables(conn) - remote_tbls <- tools::file_path_sans_ext(basename(urls)) - - if(all(remote_tbls %in% current_tbls)) return(conn) - urls <- urls[!(remote_tbls %in% current_tbls)] - - # use CREATE TABLE for persistent local copy - # use CREATE VIEW for remote parquet connection instead - CMD <- "CREATE TABLE" - if(!local) CMD <- "CREATE VIEW" - - - # httpfs crashes windows, use local parquet - CMD <- "CREATE VIEW" - urls <- download_cache(urls) - - - - send_query <- purrr::possibly(DBI::dbSendQuery, otherwise=NULL) - - for(i in seq_along(urls)){ - url <- urls[[i]] - tblname <- tools::file_path_sans_ext(tablenames[[i]]) - view_query <- glue::glue(CMD, " '{tblname}' ", - "AS SELECT * FROM parquet_scan('{url}');") - send_query(conn, view_query) - } - invisible(conn) -} - -download_cache <- function(urls) { - ids <- lapply(urls, contentid::store) - vapply(ids, contentid::resolve, character(1L)) -} \ No newline at end of file diff --git a/R/fb_import.R b/R/fb_import.R deleted file mode 100644 index 356d3c2..0000000 --- a/R/fb_import.R +++ /dev/null @@ -1,32 +0,0 @@ -#' Import tables to local store -#' -#' @param server fishbase or sealifebase -#' @param version release version -#' @param db A cachable duckdb database connection -#' @param tables list of tables to import. Default `NULL` will -#' import all tables. -#' @details Downloads and stores tables from the requested version of -#' fishbase or sealifebase. If the table is already downloaded, it will -#' not be re-downloaded. Imported tables are added to the active duckdb -#' connection. Note that there is no need to call this -#' @export -#' @examplesIf interactive() -#' conn <- fb_import() -fb_import <- function(server = c("fishbase","sealifebase"), - version=get_latest_release(), - db = fb_conn(server, version), - tables = NULL) { - - meta <- parse_prov(read_prov(server), version) - if(!is.null(tables)) { - meta <- meta[meta$name %in% tables,] - } - - missing <- is.na(meta$url) - if(any(missing)) { - meta$url[missing] <- resolve_ids(meta$id[missing]) - } - - - duckdb_import(meta$url, meta$name, db) -} diff --git a/R/fb_tbl.R b/R/fb_tbl.R index 7aaac49..193ab57 100644 --- a/R/fb_tbl.R +++ b/R/fb_tbl.R @@ -1,30 +1,129 @@ -#' #' Access a fishbase or sealifebase table +#' +#' +#' Please note that rfishbase accesses static snapshots of the raw database +#' tables used by FishBase and Sealifebase websites. Because these are static +#' snapshots, they may lag behind the latest available information on the web +#' interface, but should provide stable results. +#' +#' Please also note that the website pages are not organized precisely along +#' the lines of these tables. A given page for a species may draw on data from +#' multiple tables, and sometimes presents the data in a processed or summarized +#' form. Following RDB design, it is often +#' necessary to join multiple tables. Other data cleaning steps are sometimes +#' necessary as well. #' @param tbl table name, as it appears in the database. See [fb_tables()] #' for a list. +#' @param server Access data from fishbase or sealifebase? +#' @param version Version, see [available_releases()] +#' @param db database connection, deprecated #' @param collect should we return an in-memory table? Generally best to leave #' as TRUE unless RAM is too limited. A remote table can be used with most #' dplyr functions (filter, select, joins, etc) to further refine. -#' @inheritParams fb_import #' @export #' @examplesIf interactive() #' fb_tbl("species") -fb_tbl <- - function(tbl, - server = c("fishbase", "sealifebase"), - version = "latest", - db = fb_conn(server, version), - collect = TRUE){ - - - db <- fb_import(server, version, db, tbl) - out <- dplyr::tbl(db, tbl) - if(!collect) return(out) - dplyr::collect(out) - } +fb_tbl <- function(tbl, + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, + collect = TRUE) { + urls <- fb_urls(server, version) + names(urls) <- tbl_name(urls) + out <- duckdbfs::open_dataset(urls[tbl]) + + if(collect) out <- dplyr::collect(out) + + out +} + +#' List the tables available on fishbase/sealifebase +#' +#' These table names can be used to access each of the corresponding tables +#' using `[fb_tbl()]`. Please note that following RDB design, it is often +#' necessary to join multiple tables. Other data cleaning steps are sometimes +#' necessary as well. +#' @inheritParams fb_tbl +#' @export +#' @examplesIf interactive() +#' fb_tables() +fb_tables <- function(server = c("fishbase", "sealifebase"), + version = "latest") { + fb_urls(server, version) |> tbl_name() + +} - -#' @importFrom magrittr `%>%` +#' List available releases +#' +#' @param server fishbase or sealifebase #' @export -magrittr::`%>%` -FISHBASE_API <- "fishbase" \ No newline at end of file +#' @examplesIf interactive() +#' available_releases() +available_releases <- function(server = c("fishbase", "sealifebase")) { + + sv <- server_code(server) + repo <- "datasets/cboettig/fishbase" + path <- glue::glue("data/{sv}") + hf <- "https://huggingface.co" + branch <- "main" + versions <- + glue::glue("{hf}/api/{repo}/tree/{branch}/{path}") |> + jsonlite::read_json() |> + purrr::map_chr('path') |> + stringr::str_extract("\\/v(\\d{2}\\.\\d{2})", 1) + + versions + +} + + +get_latest_release <- function() "latest" + + +hf_urls <- function(path = "data/fb/v24.07/parquet", + repo = "datasets/cboettig/fishbase", + branch = "main" +) { + + hf <- "https://huggingface.co" + paths <- + glue::glue("{hf}/api/{repo}/tree/{branch}/{path}") |> + jsonlite::read_json() |> + purrr::map_chr('path') + + glue::glue("{hf}/{repo}/resolve/{branch}/{path}", path=paths) +} + + + +fb_urls <- function(server = c("fishbase", "sealifebase"), + version = "latest") { + + releases <- available_releases(server) + if (version == "latest") { + version <- max(releases) + } + if ( !(version %in% releases) ) { + stop( + glue::glue("version {version} not in ", + glue::glue_collapse( + glue::glue("{releases}"), ", ", last = " or ")) + ) + } + + sv <- server_code(server) + path <- glue::glue("data/{sv}/v{version}/parquet") + hf_urls(path) +} + +server_code <- function(server = c("fishbase", "sealifebase")) { + server <- match.arg(server) + switch(server, + "fishbase" = "fb", + "sealifebase" = "slb") +} + + +tbl_name <- function(urls) { + stringr::str_remove(basename(urls), ".parquet") +} diff --git a/R/fishbase.R b/R/fishbase.R index dfea9d9..c3383a0 100644 --- a/R/fishbase.R +++ b/R/fishbase.R @@ -6,11 +6,11 @@ #' nearly 200,000 species records for all types of aquatic life not covered by #' FishBase.' #' @aliases rfishbase -#' @docType package -#' @title The new R interface to Fishbase, v2.0 +#' @docType _PACKAGE +#' @title The new R interface to Fishbase, v5.0 #' @author Carl Boettiger \email{carl@@ropensci.org} #' @author Scott Chamberlain \email{scott@@ropensci.org} #' @keywords package -NULL + diff --git a/R/load_taxa.R b/R/load_taxa.R index 33d5e0c..51153ca 100644 --- a/R/load_taxa.R +++ b/R/load_taxa.R @@ -1,39 +1,36 @@ -#' load_taxa -#' -#' @param server Either "fishbase" (the default) or "sealifebase" -#' @param version the version of the database you want. Will default to the -#' latest avialable; see [available_releases()]. -#' @param db A remote database connection. Will default to the best available -#' system, see [default_db()]. -#' @param collect return a data.frame if TRUE, otherwise, a DBI connection to -#' the table in the database -#' @param ... for compatibility with previous versions -#' @return the taxa list -#' @export -load_taxa <- function(server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), - collect = TRUE, + +load_taxa_ <- function(server = c("fishbase", "sealifebase"), + version = "latest", ...){ - - #db_tbl <- tbl_name("taxa", server, version) - #if(has_table(db_tbl)) return(dplyr::tbl(db, db_tbl)) - + server <- match.arg(server) ## SeaLifeBase requires a different taxa table function: - if(is.null(server)) server <- getOption("FISHBASE_API", FISHBASE_API) if(grepl("sealifebase", server)){ - taxa_table <- slb_taxa_table(server, version, db) + taxa_table <- slb_taxa_table(version) } else { - taxa_table<- fb_taxa_table(server, version, db) + taxa_table <- fb_taxa_table(version) } - if(collect) return(dplyr::collect(taxa_table)) - taxa_table } - +#' load_taxa +#' +#' @param server Either "fishbase" (the default) or "sealifebase" +#' @param version the version of the database you want. Will default to the +#' latest available; see [available_releases()]. +#' @param ... for compatibility with previous versions +#' @return the taxa list +#' @export +load_taxa <- memoise::memoise(load_taxa_) + + + +dummy_fn <- function(f) { + # CRAN check doesn't recognize memoise use in the above and throws note: + # Namespace in Imports field not imported from: ‘memoise’ + memoise::memoise(f) +} @@ -41,28 +38,27 @@ globalVariables(c("SpecCode", "Species", "Genus", "Subfamily", "Family", "Order", "Class", "SuperClass", "Phylum", "Kingdom", "tempcolumn")) -fb_taxa_table <- - function(server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version)){ +fb_taxa_table <- function(version = "latest", db = NULL){ + + server <- "fishbase" - taxon_species <- fb_tbl("species", server, version, db) %>% + taxon_species <- fb_tbl("species", server, version, db, collect=FALSE) %>% select("SpecCode", "Species", "Genus", "Subfamily", - "GenCode", "SubGenCode", "FamCode") + "GenCode", "SubGenCode", "FamCode") - taxon_genus <- fb_tbl("genera", server, version, db) %>% + taxon_genus <- fb_tbl("genera", server, version, db, collect=FALSE) %>% select("GenCode", "GenName", "GenusCommonName" = "GenComName", "FamCode", "Subfamily", "SubgenusOf") - taxon_family <- fb_tbl("families", server, version, db) %>% + taxon_family <- fb_tbl("families", server, version, db, collect=FALSE) %>% select("FamCode", "Family","FamilyCommonName" = "CommonName", "Order", "Ordnum", "Class", "ClassNum") - taxon_order <- fb_tbl("orders", server, version, db) %>% + taxon_order <- fb_tbl("orders", server, version, db, collect=FALSE) %>% select("Ordnum", "Order", "OrderCommonName" = "CommonName", "ClassNum", "Class") - taxon_class <- fb_tbl("classes", server, version, db) %>% + taxon_class <- fb_tbl("classes", server, version, db, collect=FALSE) %>% select("ClassNum", "Class", "ClassCommonName" = "CommonName", "SuperClass", "Subclass") @@ -78,7 +74,7 @@ fb_taxa_table <- dplyr::select("SpecCode", "Species", "Genus", "Subfamily", "Family", "Order", "Class", "SuperClass") %>% dplyr::mutate(Species = paste(Genus, Species)) %>% - dplyr::compute(temporary=FALSE) + dplyr::collect() taxa_table @@ -87,7 +83,7 @@ fb_taxa_table <- -slb_taxa_table <- function(server, version, db){ +slb_taxa_table <- function(version = "latest", db=NULL){ server <- "sealifebase" @@ -95,7 +91,8 @@ slb_taxa_table <- function(server, version, db){ select("SpecCode", "Species", "Genus", "GenCode", "SubGenCode", "FamCode") taxon_genus <- fb_tbl("genera", server, version, db) %>% - select("GenCode", "Genus" = "GEN_NAME", "GenusCommonName" = "CommonName", "FamCode" = "Famcode", + select("GenCode", "Genus" = "GEN_NAME", + "GenusCommonName" = "CommonName", "FamCode" = "Famcode", "Subfamily") taxon_family <- fb_tbl("families", server, version, db) %>% select("FamCode", "Family","FamilyCommonName"="CommonName", "Order", diff --git a/R/local_db.R b/R/local_db.R deleted file mode 100644 index 5fc8716..0000000 --- a/R/local_db.R +++ /dev/null @@ -1,77 +0,0 @@ - -#' Cacheable database connection -#' @inheritParams fb_import -#' @importFrom fs path dir_create dir_ls -#' @export -fb_conn <- function(server = c("fishbase", "sealifebase"), - version = "latest"){ - - - local <- getOption("rfishbase_local_db", FALSE) - if(!local) { - dir <- ":memory:" - } else { - dir <- db_dir() - } - - server <- match.arg(server) - - if(version == "latest"){ - version <- get_latest_release(server) - } - db_name <- paste(server,version, sep="_") - db <- mget(db_name, envir = rfishbase_cache, ifnotfound = NA)[[1]] - path <- dir - if(fs::dir_exists(dir)) - path <- fs::path(dir, db_name) - if(!inherits(db, "duckdb_connection")){ - db <- DBI::dbConnect(drv = duckdb::duckdb(), path) - assign(db_name, db, envir = rfishbase_cache) - } - db -} - -rfishbase_cache <- new.env() - -# internal alias -default_db <- fb_conn - -#' disconnect the database -#' @param db optional, an existing pointer to the db, e.g. from [fb_conn()] -#' or [fb_import()]. -#' @export -db_disconnect <- function(db = NULL){ - if(!is.null(db)){ - if(inherits(db, "duckdb_connection")) { - DBI::dbDisconnect(db, shutdown=TRUE) - } - } - db_name <- ls(envir = rfishbase_cache) - for(cached in db_name) { - db <- mget(cached, envir = rfishbase_cache, ifnotfound = NA)[[1]] - remove(list = cached, envir = rfishbase_cache) - if(inherits(db, "duckdb_connection")) { - duckdb::dbDisconnect(db, shutdown=TRUE) - } - - } -} - - -#' show fishbase directory -#' -#' @export -#' @importFrom tools R_user_dir -db_dir <- function(){ - dir <- Sys.getenv("FISHBASE_HOME", tools::R_user_dir("rfishbase")) - if(!fs::dir_exists(dir)) { - fs::dir_create(dir) - } - dir -} - - -fish_db <- function(version = "latest"){ - db = fb_conn(version = version) - fb_import("fishbase", version = version, db) -} diff --git a/R/parquet_db.R b/R/parquet_db.R deleted file mode 100644 index f60f507..0000000 --- a/R/parquet_db.R +++ /dev/null @@ -1,95 +0,0 @@ - -#' fb_tables -#' list tables -#' @inheritParams fb_import -#' @export -fb_tables <- function(server = c("fishbase", "sealifebase"), - version = "latest"){ - - prov_document <- read_prov(server) - meta_df <- parse_prov(prov_document, version = version) - meta_df$name -} - - -parse_prov_ <- - function(prov = read_prov(), version = "latest") { - who <- names(prov) - if ("@graph" %in% who) { - prov <- prov[["@graph"]] - } else { - prov <- list(prov) - } - avail_versions <- map_chr(prov, "version") - if (version == "latest") { - version <- max(avail_versions) - } - i <- which(version == avail_versions) - dataset <- prov[[i]] - - meta <- dataset$distribution - - # The pattern "map("term") |> map_chr(1)" takes first-match if multiples are found - meta_df <- tibble::tibble( - name = purrr::map(meta, "name", .default=NA) %>% - purrr::map_chr(1) %>% tools::file_path_sans_ext(), - id = purrr::map_chr(meta, "id", .default=NA), - description = purrr::map_chr(meta, "description", .default=NA), - format = purrr::map(meta, "encodingFormat", .default=NA) |> map_chr(1), - type = purrr::map_chr(meta, "type", .default=NA), - url = purrr::map(meta, "contentUrl", .default=NA) |> map_chr(1) - ) - meta_df[meta_df$type == "DataDownload",] -} -parse_prov <- memoise::memoise(parse_prov_) - -dummy_memoise <- function(f, ...) { - memoise::memoise(f, ...) -} - - -create_view <- function(parquets, - tblnames, - conn = DBI::dbConnect(drv = duckdb::duckdb())) { - purrr::walk2(parquets, tblnames, create_view, conn) - conn -} - -read_prov_ <-function(server = c("fishbase", "sealifebase"), - local=getOption("rfishbase_local_prov", - FALSE)) { - server <- match.arg(server) - prov_latest <- - switch(server, - fishbase = "https://github.com/ropensci/rfishbase/raw/master/inst/prov/fb.prov", - sealifebase = "https://github.com/ropensci/rfishbase/raw/master/prov/slb.prov") - - prov_local <- - switch( - server, - fishbase = system.file("prov", "fb.prov", package = "rfishbase"), - sealifebase = system.file("prov", "slb.prov", package = "rfishbase") - ) - - if(local) return(jsonlite::read_json(prov_local)) - - - prov <- purrr::possibly(jsonlite::read_json, - otherwise = jsonlite::read_json(prov_local)) - suppressWarnings({ - out <- prov(prov_latest) - }) - out -} -read_prov <- memoise::memoise(read_prov_) - - -resolve_ids_ <- function(ids) { - suppressMessages({ - purrr::map_chr(ids, - contentid::resolve, - store = TRUE, - dir = db_dir()) - }) -} -resolve_ids <- memoise::memoise(resolve_ids_) diff --git a/R/rstudio_pane.R b/R/rstudio_pane.R deleted file mode 100644 index 3e0eda7..0000000 --- a/R/rstudio_pane.R +++ /dev/null @@ -1,119 +0,0 @@ - -#' Open database connection pane in RStudio -#' -#' This function launches the RStudio "Connection" pane to interactively -#' explore the database. -#' -#' @return NULL -#' @export -#' -#' @examplesIf interactive() -#' -#' if (!is.null(getOption("connectionObserver"))) fishbase_pane() -fishbase_pane <- function() { - observer <- getOption("connectionObserver") - if (!is.null(observer) && interactive()) { - observer$connectionOpened( - type = "fishbase", - host = "rfishbase", - displayName = "FishBase Tables", - icon = system.file("img", "logo.png", package = "rfishbase"), - connectCode = "rfishbase::fishbase_pane()", - disconnect = db_disconnect, - listObjectTypes = function() { - list( - table = list(contains = "data") - ) - }, - listObjects = function(type = "datasets") { - tbls <- DBI::dbListTables(fish_db()) - data.frame( - name = tbls, - type = rep("table", length(tbls)), - stringsAsFactors = FALSE - ) - }, - listColumns = function(table) { - res <- DBI::dbGetQuery(fish_db(), - paste0("SELECT * FROM \"", table, "\" LIMIT 10")) - data.frame( - name = names(res), - type = vapply(res, function(x) class(x)[1], character(1)), - stringsAsFactors = FALSE - ) - }, - previewObject = function(rowLimit, table) { #nolint - DBI::dbGetQuery(fish_db(), - paste0("SELECT * FROM \"", table, "\" LIMIT ", rowLimit)) - }, - actions = list( - Status = list( - icon = system.file("img", "logo.png", package = "rfishbase"), - callback = fish_db_status - ), - SQL = list( - icon = system.file("img", "edit-sql.png", package = "rfishbase"), - callback = sql_action - ) - ), - connectionObject = fish_db() - ) - } -} - -update_fishbase_pane <- function() { - observer <- getOption("connectionObserver") - if (!is.null(observer)) { - observer$connectionUpdated("FishBase", "neonstore", "") - } -} - -sql_action <- function() { - if (requireNamespace("rstudioapi", quietly = TRUE) && - exists("documentNew", asNamespace("rstudioapi"))) { - contents <- paste( - "-- !preview conn=neonstore::fish_db()", - "", - "SELECT * FROM provenance LIMIT 10", - "", - sep = "\n" - ) - - rstudioapi::documentNew( - text = contents, type = "sql", - position = rstudioapi::document_position(2, 40), - execute = FALSE - ) - } -} - -fish_db_status <- function () { - con <- fish_db() - inherits(con, "DBIConnection") -} - - -## Do not open the pane onAttach, wait for user to call fishbase_pane() -#.onAttach <- function(libname, pkgname) { #nolint -# if (interactive() && Sys.getenv("RSTUDIO") == "1" && !in_chk()) { -# tryCatch({fishbase_pane()}, error = function(e) NULL, finally = NULL) -# } -# if (interactive()) -# tryCatch(fish_db_status(), error = function(e) NULL, finally = NULL) -#} - - -in_chk <- function() { - any( - grepl("check", - sapply(sys.calls(), - function(a) paste(deparse(a), collapse = "\n")) - ) - ) -} - -## Shouldn't be required globally, but seems that RStudio panel -## now tries to automate creation of the connections pane but doesn't do it correctly, -## or else duckdb implementation is missing some feature. -options(rstudio.connectionObserver.errorsSuppressed = TRUE) - diff --git a/R/species.R b/R/species.R index a614dc1..c74d784 100644 --- a/R/species.R +++ b/R/species.R @@ -2,14 +2,11 @@ #' #' Provide wrapper to work with species lists. #' @param species_list A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned. -#' @param server can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -#' easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -#' `Sys.setenv(FISHBASE_API="sealifebase")`. -#' @param version a version string for the database, will default to the latest release. see [get_releases()] for details. -#' @param db the -#' @param fields a character vector specifying which fields (columns) should be returned. By default, -#' all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later -#' @param ... unused; for backwards compatibility only +#' @param server Either "fishbase" or "sealifebase". +#' @param version a version string for the database. See [available_releases()] for details. +#' @param fields subset to these columns. (recommend to omit this and handle manually) +#' @param db database connection, now deprecated. +#' @param ... additional arguments, currently ignored #' @return a data.frame with rows for species and columns for the fields returned by the query (FishBase 'species' table) #' @details #' The Species table is the heart of FishBase. This function provides a convenient way to @@ -17,67 +14,11 @@ #' For details, see: http://www.fishbase.org/manual/english/fishbasethe_species_table.htm #' #' Species scientific names are defined according to fishbase taxonomy and nomenclature. -#' -#' @importFrom methods as is -#' @importFrom utils data lsf.str packageVersion -#' @export species -#' @aliases species species_info +#' @export #' @examples #' \dontrun{ #' #' species(c("Labroides bicolor", "Bolbometopon muricatum")) -#' species(c("Labroides bicolor", "Bolbometopon muricatum"), fields = species_fields$habitat) #' #' } species <- endpoint("species") - -#species <- endpoint("species", tidy_table = tidy_species_table) -#' @importFrom readr read_csv -load_species_meta <- memoise::memoise(function(){ - meta <- system.file("metadata", "species.csv", package="rfishbase") - species_meta <- as.data.frame(readr::read_csv(meta, col_types = "cclc")) - row.names(species_meta) <- species_meta$field - species_meta -}) - -## helper routine for tidying species data -tidy_species_table <- function(df) { - - - species_meta <- load_species_meta() - # Convert columns to the appropriate class - for(i in names(df)){ - class <- as.character(species_meta[[i, "class"]]) - if(class=="Date"){ - df[[i]] <- as.Date(df[[i]]) - } else if(class=="logical"){ - df[[i]] <- as(as.numeric(as.character(df[[i]])), class) - } else { - df[[i]] <- as(as.character(df[[i]]), class) - # Will warn when class=integer & value is NA - } - } - ## Drop useless columns. - # keep <- species_meta$field[species_meta$keep] - # keep_id <- match(keep, names(df)) - # keep_id <- keep_id[!is.na(keep_id)] - # df <- df[,keep_id] - - - df -} -## Metadata used by tidy_species_table, created into data_raw() - - - - -#' A list of the species_fields available -#' -#' @name species_fields -#' @docType data -#' @author Carl Boettiger \email{carl@@ropensci.org} -#' @keywords data -NULL - - - diff --git a/R/species_list.R b/R/species_list.R deleted file mode 100644 index 5e8bd61..0000000 --- a/R/species_list.R +++ /dev/null @@ -1,65 +0,0 @@ -#' species_list -#' -#' Return the a species list given a taxonomic group -#' @param SuperClass Request all species of this Superclass -#' @param Class Request all species in this taxonomic Class -#' @param Order Request all species in this taxonomic Order -#' @param Family Request all species in this taxonomic Family -#' @param Subfamily Request all species in this taxonomic SubFamily -#' @param Genus Request all species in this taxonomic Genus -#' @param Species Request all species in this taxonomic Species -#' @param SpecCode Request species name of species matching this SpecCode -#' @param server fishbase or sealifebase -#' @examplesIf interactive() -#' \donttest{ -#' ## All species in the Family -#' species_list(Family = 'Scaridae') -#' ## All species in the Genus -#' species_list(Genus = 'Labroides') -#' } -#' @export -#' @importFrom dplyr enquo -#' @importFrom rlang !! -species_list <- function(Class = NULL, - Order = NULL, - Family = NULL, - Subfamily = NULL, - Genus = NULL, - Species = NULL, - SpecCode = NULL, - SuperClass = NULL, - server = getOption("FISHBASE_API", FISHBASE_API)){ - ## This is a terribly designed function, since it's design is - ## ambiguous about how multiple non-null arguments should be treated! - class <- enquo(Class) - order <- enquo(Order) - family <- enquo(Family) - subfamily <- enquo(Subfamily) - genus <- enquo(Genus) - species <- enquo(Species) - superclass <- enquo(SuperClass) - spec_code <- enquo(SpecCode) - #if(!is.nullClass) - taxa <- load_taxa(server) - if(!is.null(SuperClass)) - taxa <- taxa %>% filter(SuperClass %in% !!superclass) - if(!is.null(Class)) - taxa <- taxa %>% filter(Class %in% !!class) - if(!is.null(Order)) - taxa <- taxa %>% filter(Order %in% !!order) - if(!is.null(Family)) - taxa <- taxa %>% filter(Family %in% !!family) - if(!is.null(Subfamily)) - taxa <- taxa %>% filter(Subfamily %in% !!subfamily) - if(!is.null(Genus)) - taxa <- taxa %>% filter(Genus %in% !!genus) - if(!is.null(Species)) - taxa <- taxa %>% filter(Species %in% !!species) - if(!is.null(SpecCode)) - taxa <- taxa %>% filter(SpecCode %in% !!spec_code) - - taxa %>% pull(Species) - -} - - diff --git a/R/species_names.R b/R/species_names.R deleted file mode 100644 index 2100295..0000000 --- a/R/species_names.R +++ /dev/null @@ -1,18 +0,0 @@ -#' species names -#' -#' returns species names given FishBase's SpecCodes -#' -#' @param codes a vector of speccodes (e.g. column from a table) -#' @return A character vector of species names for the SpecCodes -#' @inheritParams species -#' @export species_names -#' @aliases species_names -species_names <- function(codes, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db()){ - - fb_species(server, version, db) %>% filter(SpecCode %in% codes) %>% collect() -} - - diff --git a/R/synonyms.R b/R/synonyms.R index 18eba49..e6a45b1 100644 --- a/R/synonyms.R +++ b/R/synonyms.R @@ -22,38 +22,38 @@ # species("Bolbometopon muricatum") # } synonyms <- function(species_list = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ...){ + server <- match.arg(server) - if (is.null(server)) - server <- getOption("FISHBASE_API", FISHBASE_API) if (!grepl("sealifebase", server)) { syn <- fb_tbl("synonyms", server, version, db) %>% mutate(synonym = paste(SynGenus, SynSpecies)) %>% - select(synonym, Status, SpecCode, SynCode, - CoL_ID, TSN, WoRMS_ID, ZooBank_ID, - TaxonLevel) + select(dplyr::any_of(c("synonym", "Status", "SpecCode", "SynCode", + "CoL_ID", "TSN", "WoRMS_ID", "ZooBank_ID", + "TaxonLevel"))) } else { syn <- fb_tbl("synonyms", server, version, db) %>% mutate(synonym = paste(SynGenus, SynSpecies)) %>% - select("synonym", "Status", "SpecCode", "SynCode", + select(dplyr::any_of(c("synonym", "Status", "SpecCode", "SynCode", "CoL_ID", "TSN", "ZooBank_ID", - "TaxonLevel") + "TaxonLevel"))) } if(is.null(species_list)) - return(collect(syn)) + return(syn) df <- data.frame(synonym = species_list, stringsAsFactors = FALSE) - - left_join(df, syn, by="synonym") %>% - left_join(fb_species(server, version, db), by = "SpecCode") %>% - collect() + codes <- fb_species(server, version) + dplyr::left_join(df, syn, by="synonym", + relationship = "many-to-many" + ) %>% + dplyr::left_join(codes, by = "SpecCode") } diff --git a/README.Rmd b/README.Rmd index 37606b6..55e6b33 100644 --- a/README.Rmd +++ b/README.Rmd @@ -13,9 +13,30 @@ output: github_document [![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/rfishbase)](https://github.com/r-hub/cranlogs.app) +Welcome to `rfishbase 5`! This is the fourth rewrite of the original `rfishbase` package described in [Boettiger et al. (2012)](https://doi.org/10.1111/j.1095-8649.2012.03464.x). -Welcome to `rfishbase 4`. This is the fourth rewrite of the original `rfishbase` package described in [Boettiger et al. (2012)](https://doi.org/10.1111/j.1095-8649.2012.03464.x). +Another streamlined re-design following new abilities for data hosting and access. +This release relies on a HuggingFace datasets hosting for data and metadata hosting +in parquet and schema.org. + +Data access is simplified to use the simple HuggingFace datasets API instead +of the previous contentid-based resolution. This allows metadata to be defined +with directly alongside the data platform independent of the R package. + +A simplified access protocol relies on `duckdbfs` for direct reads of tables. +Several functions previously used only to manage connections are now deprecated +or removed, along with a significant number of dependencies. + +Core use still centers around the same package API using the `fb_tbl()` function, +with legacy helper functions for common tables like `species()` are still accessible and +can still optionally filter by species name where appropriate. As before, loading the +full tables and sub-setting manually is still recommended. + +Historic helper functions like `load_taxa()` (combining the taxonomic classification from Species, +Genus, Family and Order tables), `validate_names()`, and `common_to_sci()` and +`sci_to_common()` should be in working order, all using table-based outputs. + - `rfishbase 1.0` relied on parsing of XML pages served directly from Fishbase.org. - `rfishbase 2.0` relied on calls to a ruby-based API, `fishbaseapi`, that provided access to SQL snapshots of about 20 of the more popular tables in FishBase or SeaLifeBase. @@ -91,61 +112,6 @@ available_releases() ``` - -## Low-memory environments - -If you have very limited RAM (e.g. <= 1 GB available) it may be helpful to use `fishbase` tables in remote form by setting `collect = FALSE`. This allows the tables to remain on disk, while the user is still able to use almost all `dplyr` functions (see the `dbplyr` vignette). Once the table is appropriately subset, the user will need to call `dplyr::collect()` to use generic non-dplyr functions, such as plotting commands. - -```{r} -fb_tbl("occurrence") -``` - - -## Local copy - -Set the option "rfishbase_local_db" = TRUE to create a local copy, otherwise will use a remote copy. -Local copy will get better performance after initial import, but may experience conflicts when -`duckdb` is upgraded or when multiple sessions attempt to access the directory. Remove the default -storage directory (given by `db_dir()`) after upgrading duckdb if using a local copy. - -```{r} -options("rfishbase_local_db" = TRUE) -db_disconnect() # close previous remote connection - -conn <- fb_conn() -conn -``` - -Users can trigger a one-time download of all fishbase tables (or a list of desired tables) using `fb_import()`. This will ensure later use of any function can operate smoothly even when no internet connection is available. Any table already downloaded will not be re-downloaded. (Note: `fb_import()` also returns a remote duckdb database connection to the tables, for users who prefer to work with the remote data objects.) - -```{r} -fb_import() -``` - - - -```{r include=FALSE} -db_disconnect(conn) -``` - - - -## Interactive RStudio pane - -RStudio users can also browse all fishbase tables interactively in the RStudio connection browser by using the function `fisbase_pane()`. Note that this function will first download a complete set of the fishbase tables. - -## Backwards compatibility - - -`rfishbase` 4.0 tries to maintain as much backwards compatibility as possible with rfishbase 3.0. Because parquet preserves native data types, some encoded types may differ from earlier versions. As before, these are not always the native type -- e.g. fishbase encodes some boolean (logical TRUE/FALSE) values as integer (-1, 0) or character types. Use `as.logical()` to coerce into the appropriate type in that case. - -Toggling between fishbase and sealifebase servers using an environmental variable, `FISHBASE_API`, is now deprecated. - -Note that fishbase will store downloaded files by hash in the app directory, given by `db_dir()`. The default location can be set by configuring the desired path in the environmental variable, `FISHBASE_HOME`. - - - - ----------- Please note that this package is released with a [Contributor Code of Conduct](https://ropensci.org/code-of-conduct/). By contributing to this project, you agree to abide by its terms. diff --git a/README.md b/README.md index 3e0da73..fd15e6e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ -[![R-CMD-check](https://github.com/ropensci/rfishbase/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/rfishbase/actions) +[![R-CMD-check](https://github.com/ropensci/rfishbase/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ropensci/rfishbase/actions/workflows/R-CMD-check.yaml) [![Coverage status](https://codecov.io/gh/ropensci/rfishbase/branch/master/graph/badge.svg)](https://codecov.io/github/ropensci/rfishbase?branch=master) [![Onboarding](https://badges.ropensci.org/137_status.svg)](https://github.com/ropensci/software-review/issues/137) @@ -12,10 +12,35 @@ status](https://www.r-pkg.org/badges/version/rfishbase)](https://cran.r-project. [![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/rfishbase)](https://github.com/r-hub/cranlogs.app) -Welcome to `rfishbase 4`. This is the fourth rewrite of the original +Welcome to `rfishbase 5`! This is the fourth rewrite of the original `rfishbase` package described in [Boettiger et al. (2012)](https://doi.org/10.1111/j.1095-8649.2012.03464.x). +Another streamlined re-design following new abilities for data hosting +and access. This release relies on a HuggingFace datasets hosting for +data and metadata hosting in parquet and schema.org. + +Data access is simplified to use the simple HuggingFace datasets API +instead of the previous contentid-based resolution. This allows metadata +to be defined with directly alongside the data platform independent of +the R package. + +A simplified access protocol relies on `duckdbfs` for direct reads of +tables. Several functions previously used only to manage connections are +now deprecated or removed, along with a significant number of +dependencies. + +Core use still centers around the same package API using the `fb_tbl()` +function, with legacy helper functions for common tables like +`species()` are still accessible and can still optionally filter by +species name where appropriate. As before, loading the full tables and +sub-setting manually is still recommended. + +Historic helper functions like `load_taxa()` (combining the taxonomic +classification from Species, Genus, Family and Order tables), +`validate_names()`, and `common_to_sci()` and `sci_to_common()` should +be in working order, all using table-based outputs. + - `rfishbase 1.0` relied on parsing of XML pages served directly from Fishbase.org. - `rfishbase 2.0` relied on calls to a ruby-based API, `fishbaseapi`, @@ -57,24 +82,23 @@ function: fb_tbl("ecosystem") ``` - # A tibble: 157,870 × 18 - autoctr E_CODE Ecosy…¹ Specc…² Stock…³ Status Curre…⁴ Abund…⁵ LifeS…⁶ Remarks - - 1 1 1 50628 549 565 native Present adults - 2 2 1 189 552 568 native Present adults - 3 3 1 189 554 570 native Present adults - 4 4 1 79732 873 889 native Present adults - 5 5 1 5217 948 964 native Present adults - 6 7 1 39852 956 972 native Present adults - 7 8 1 39852 957 973 native Present adults - 8 9 1 39852 958 974 native Present adults - 9 10 1 188 1526 1719 native Present adults - 10 11 1 188 1626 1819 native Present adults - # … with 157,860 more rows, 8 more variables: Entered , - # Dateentered , Modified , Datemodified , Expert , - # Datechecked , WebURL , TS , and abbreviated variable names - # ¹​EcosystemRefno, ²​Speccode, ³​Stockcode, ⁴​CurrentPresence, ⁵​Abundance, - # ⁶​LifeStage + # A tibble: 160,334 × 18 + autoctr E_CODE EcosystemRefno Speccode Stockcode Status CurrentPresence + + 1 1 1 50628 549 565 native Present + 2 2 1 189 552 568 native Present + 3 3 1 189 554 570 native Present + 4 4 1 79732 873 889 native Present + 5 5 1 5217 948 964 native Present + 6 7 1 39852 956 972 native Present + 7 8 1 39852 957 973 native Present + 8 9 1 39852 958 974 native Present + 9 10 1 188 1526 1719 native Present + 10 11 1 188 1626 1819 native Present + # ℹ 160,324 more rows + # ℹ 11 more variables: Abundance , LifeStage , Remarks , + # Entered , Dateentered , Modified , Datemodified , + # Expert , Datechecked , WebURL , TS You can see all the tables using `fb_tables()` to see a list of all the table names (specify `sealifebase` if desired). Careful, there are a lot @@ -115,26 +139,26 @@ parallels the database structure of Fishbase. As such, almost all fb_tbl("species", "sealifebase") ``` - # A tibble: 103,169 × 109 - SpecCode Genus Species Author Speci…¹ FBname FamCode Subfa…² GenCode TaxIs…³ - - 1 10217 Abyss… cidaris Poore… 3113 512 9280 0 - 2 10218 Abyss… panope Poore… 3113 512 9280 0 - 3 90399 Abyss… averin… Kussa… 3113 502 17490 0 - 4 52610 Abyss… millari Monni… 2585 978 9281 0 - 5 52611 Abyss… wyvill… Herdm… 2892 978 9281 0 - 6 138684 Abyss… planus (Slad… 81020 1615 24229 0 - 7 90400 Abyss… acutil… Doti … 3113 587 9282 0 - 8 10219 Abyss… argent… Menzi… 3113 587 9282 0 - 9 10220 Abyss… bathya… Just,… 3113 587 9282 0 - 10 10221 Abyss… dentif… Menzi… 3113 587 9282 0 - # … with 103,159 more rows, 99 more variables: Remark , - # PicPreferredName , PicPreferredNameM , PicPreferredNameF , - # PicPreferredNameJ , Source , AuthorRef , SubGenCode , - # Fresh , Brack , Saltwater , Land , BodyShapeI , - # DemersPelag , AnaCat , MigratRef , DepthRangeShallow , - # DepthRangeDeep , DepthRangeRef , DepthRangeComShallow , - # DepthRangeComDeep , DepthComRef , LongevityWild , … + # A tibble: 102,464 × 111 + SpecCode Genus Species Author SpeciesRefNo FBname FamCode Subfamily GenCode + + 1 57969 Abdopus horrid… (D'Or… 96968 Red S… 1890 Octopodi… 24384 + 2 57836 Abdopus tenebr… (Smit… 19 1890 Octopodi… 24384 + 3 57142 Abdopus tongan… (Hoyl… 19 1890 Octopodi… 24384 + 4 2381155 Abdopus undula… Huffa… 84307 1890 24384 + 5 14647 Abebai… troglo… Vande… 19 572 9260 + 6 165283 Aberom… muranoi Baces… 104101 616 33537 + 7 140720 Aberra… banyul… Macki… 85340 174 9262 + 8 40346 Aberra… enigma… unspe… 19 174 9262 + 9 20199 Aberra… aberra… (Barn… 19 308 9263 + 10 93706 Aberro… verruc… Kasat… 3696 922 17969 + # ℹ 102,454 more rows + # ℹ 102 more variables: TaxIssue , Remark , PicPreferredName , + # PicPreferredNameM , PicPreferredNameF , PicPreferredNameJ , + # Source , AuthorRef , SubGenCode , Fresh , Brack , + # Saltwater , Land , BodyShapeI , DemersPelag , + # Amphibious , AmphibiousRef , AnaCat , MigratRef , + # DepthRangeShallow , DepthRangeDeep , DepthRangeRef , … ## Versions and importing all tables @@ -147,99 +171,7 @@ fishbase.org. Check available releases: available_releases() ``` - [1] "23.01" "21.06" "19.04" - -## Low-memory environments - -If you have very limited RAM (e.g. \<= 1 GB available) it may be helpful -to use `fishbase` tables in remote form by setting `collect = FALSE`. -This allows the tables to remain on disk, while the user is still able -to use almost all `dplyr` functions (see the `dbplyr` vignette). Once -the table is appropriately subset, the user will need to call -`dplyr::collect()` to use generic non-dplyr functions, such as plotting -commands. - -``` r -fb_tbl("occurrence") -``` - - # A tibble: 1,097,303 × 106 - catnum2 OccurrenceR…¹ SpecC…² Syncode Stock…³ Genus…⁴ Speci…⁵ ColName PicName - - 1 34424 36653 227 22902 241 "Megal… "cypri… "Megal… "" - 2 95154 45880 NA NA NA "" "" "" "" - 3 97606 45880 NA NA NA "" "" "" "" - 4 100025 45880 5520 25676 5809 "Johni… "belan… "" "" - 5 98993 45880 5676 16650 5969 "Chrom… "retro… "" "" - 6 99316 45880 454 23112 468 "Drepa… "punct… "" "" - 7 99676 45880 5388 145485 5647 "Gymno… "bosch… "" "" - 8 99843 45880 16813 119925 15264 "Hemir… "balin… "" "" - 9 100607 45880 8288 59635 8601 "Ostra… "rhino… "" "" - 10 101529 45880 NA NA NA "Scomb… "toloo… "" "" - # … with 1,097,293 more rows, 97 more variables: CatNum , URL , - # Station , Cruise , Gazetteer , LocalityType , - # WaterDepthMin , WaterDepthMax , AltitudeMin , - # AltitudeMax , LatitudeDeg , LatitudeMin , NorthSouth , - # LatitudeDec , LongitudeDeg , LongitudeMIn , EastWest , - # LongitudeDec , Accuracy , Salinity , LatitudeTo , - # LongitudeTo , LatitudeDegTo , LatitudeMinTo , … - -## Local copy - -Set the option “rfishbase_local_db” = TRUE to create a local copy, -otherwise will use a remote copy. Local copy will get better performance -after initial import, but may experience conflicts when `duckdb` is -upgraded or when multiple sessions attempt to access the directory. -Remove the default storage directory (given by `db_dir()`) after -upgrading duckdb if using a local copy. - -``` r -options("rfishbase_local_db" = TRUE) -db_disconnect() # close previous remote connection - -conn <- fb_conn() -conn -``` - - > - -Users can trigger a one-time download of all fishbase tables (or a list -of desired tables) using `fb_import()`. This will ensure later use of -any function can operate smoothly even when no internet connection is -available. Any table already downloaded will not be re-downloaded. -(Note: `fb_import()` also returns a remote duckdb database connection to -the tables, for users who prefer to work with the remote data objects.) - -``` r -fb_import() -``` - - > - -## Interactive RStudio pane - -RStudio users can also browse all fishbase tables interactively in the -RStudio connection browser by using the function `fisbase_pane()`. Note -that this function will first download a complete set of the fishbase -tables. - -## Backwards compatibility - -`rfishbase` 4.0 tries to maintain as much backwards compatibility as -possible with rfishbase 3.0. Because parquet preserves native data -types, some encoded types may differ from earlier versions. As before, -these are not always the native type – e.g. fishbase encodes some -boolean (logical TRUE/FALSE) values as integer (-1, 0) or character -types. Use `as.logical()` to coerce into the appropriate type in that -case. - -Toggling between fishbase and sealifebase servers using an environmental -variable, `FISHBASE_API`, is now deprecated. - -Note that fishbase will store downloaded files by hash in the app -directory, given by `db_dir()`. The default location can be set by -configuring the desired path in the environmental variable, -`FISHBASE_HOME`. + [1] "19.04" "21.06" "23.01" "23.05" "24.07" ------------------------------------------------------------------------ diff --git a/data-raw/huggingface.R b/data-raw/huggingface.R index ccc3f89..74ae0e6 100644 --- a/data-raw/huggingface.R +++ b/data-raw/huggingface.R @@ -1,4 +1,19 @@ -hf <- "https://huggingface.co" + + +fb_tbl <- function(tbl, + server = c("fishbase", "sealifebase"), + version = "latest", + collect = TRUE) { + urls <- fb_urls(server, version) + names(urls) <- tbl_name(urls) + + url <- urls[tbl] + out <- duckdbfs::open_dataset(url) + if(collect) + out <- dplyr::collect(out) + + out +} hf_urls <- function(path = "data/fb/v24.07/parquet", @@ -6,6 +21,7 @@ hf_urls <- function(path = "data/fb/v24.07/parquet", branch = "main" ) { + hf <- "https://huggingface.co" paths <- glue::glue("{hf}/api/{repo}/tree/{branch}/{path}") |> jsonlite::read_json() |> @@ -27,6 +43,7 @@ available_releases <- function(server = c("fishbase", "sealifebase")) { sv <- server_code(server) repo <- "datasets/cboettig/fishbase" path <- glue::glue("data/{sv}") + hf <- "https://huggingface.co" versions <- glue::glue("{hf}/api/{repo}/tree/{branch}/{path}") |> @@ -37,43 +54,33 @@ available_releases <- function(server = c("fishbase", "sealifebase")) { versions } -# "23.05" "23.01" "21.06" "19.04" -#url |> duckdbfs::open_dataset() fb_urls <- function(server = c("fishbase", "sealifebase"), version = "latest") { - if(version == "latest") { - version <- max(available_releases(server)) + releases <- available_releases(server) + if (version == "latest") { + version <- max(releases) } - + if ( !(version %in% releases) ) { + stop( + glue::glue("version {version} not in ", + glue::glue_collapse( + glue::glue("{releases}"), ", ", last = " or ")) + ) + } + sv <- server_code(server) - path <- glue::glue("data/{sv}/v{version}/parquet") hf_urls(path) - } fb_tables <- function(server = c("fishbase", "sealifebase"), version = "latest") { - fb_urls(server, version) |> - basename() |> - stringr::str_remove(".parquet") + fb_urls(server, version) |> tbl_name() + } -fb_table <- function(tbl, - server = c("fishbase", "sealifebase"), - version = "latest", - collect = TRUE) { - urls <- fb_urls(server, version) - tbl_names <- urls |> basename() |> stringr::str_remove(".parquet") - names(urls) <- tbl_names - url <- urls[tbl] - - out <- duckdbfs::open_dataset(url) - if(collect) - out <- dplyr::collect(out) - - out +tbl_name <- function(urls) { + stringr::str_remove(basename(urls), ".parquet") } - diff --git a/data/fields.R b/data/fields.R deleted file mode 100644 index d1f6580..0000000 --- a/data/fields.R +++ /dev/null @@ -1,72 +0,0 @@ - -## field groupings: -species_fields <- list( - id = c("SpecCode", - "Genus", - "Species", - "FBname"), - habitat = c("Fresh", - "Brack", - "Saltwater", - "DemersPelag", - "AnaCat"), - longevity = c("LongevityWild", - "LongevityCaptive", - "Vulnerability"), - depth = c("DepthRangeShallow", - "DepthRangeDeep", - "DepthRangeComShallow", - "DepthRangeComDeep"), - morph = c("Length", - "LTypeMaxM", - "LengthFemale", - "LTypeMaxF", - "CommonLength", - "LTypeComM", - "CommonLengthF", - "LTypeComF", - "Weight", - "WeightFemale"), - fishing = c("Importance", - "PriceCateg", - "PriceReliability", - "LandingStatistics", - "Landings", - "MainCatchingMethod", - "MSeines", - "MGillnets", - "MCastnets", - "MTraps", - "MSpears", - "MTrawls", - "MDredges", - "MLiftnets", - "MHooksLines", - "MOther", - "UsedforAquaculture", - "LifeCycle", - "UsedasBait", - "Aquarium", - "GameFish"), - misc = c("Dangerous", - "Electrogenic"), - curation= c("DateEntered", - "DateModified", - "DateChecked", - "Complete", - "Entered", - "Modified", - "Expert"), - refs = c("DepthRangeRef", - "LongevityWildRef", - "LongevityCapRef", - "MaxLengthRef", - "CommonLengthRef", - "MaxWeightRef", - "ImportanceRef", - "AquacultureRef", - "BaitRef", - "AquariumRef", - "GameRef", - "DangerousRef", - "ElectroRef")) diff --git a/inst/WORDLIST b/inst/WORDLIST index 13d1751..fb9c355 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,45 +1,38 @@ CBinohlan CMD -Cacheable Collette Compagno FAO FB -FISHBASE -FaoAreaList FishBASE FishBase -FishBase's Fishbase FishbaseThe Gaygusuz +HuggingFace Lmax Moutopoulos Nauen Onboarding POPCHAR +RDB README RESTful RStudio RefNo SL SeaLifeBase +Sealifebase SemVer SpecCode -SpecCodes Stergiou -SubFamily -Sys WD Wmax al -avialable bugfix -cachable -commmands +contentid countrysub countrysubref -cran csv donttest dplyr @@ -53,14 +46,13 @@ fishbaseapi fishbasethe fooditems fusiform -github +hotfix htm http https lengthfrequency memoization morphometrics -php popchar popgrowth poplf @@ -68,8 +60,6 @@ popqb rappdirs ropensci sealifebase -setenv -speccodes tbl tibble tmax diff --git a/man/available_releases.Rd b/man/available_releases.Rd index 1aabb98..c13ed6b 100644 --- a/man/available_releases.Rd +++ b/man/available_releases.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/available_releases.R +% Please edit documentation in R/fb_tbl.R \name{available_releases} \alias{available_releases} \title{List available releases} @@ -12,20 +12,8 @@ available_releases(server = c("fishbase", "sealifebase")) \description{ List available releases } -\details{ -Lists all available releases (year.month format). -To use a specific release, set the desired release using -`options(FISHBASE_VERSION=)`, as shown in the examples. -Otherwise, rfishbase will use the latest available version if this -option is unset. NOTE: it will be necessary -to clear the cache with `clear_cache()` or by restarting the R session -with a fresh environment. -} \examples{ \dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} available_releases() -options(FISHBASE_VERSION="19.04") -## unset -options(FISHBASE_VERSION=NULL) \dontshow{\}) # examplesIf} } diff --git a/man/brains.Rd b/man/brains.Rd index 279bbba..0dc8fa6 100644 --- a/man/brains.Rd +++ b/man/brains.Rd @@ -7,27 +7,24 @@ brains( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species brains diff --git a/man/c_code.Rd b/man/c_code.Rd index 4ef9364..4553d6e 100644 --- a/man/c_code.Rd +++ b/man/c_code.Rd @@ -15,26 +15,19 @@ c_code( \arguments{ \item{c_code}{a C_Code or list of C_Codes (FishBase country code)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \description{ return a table of country information for the requested c_code, as reported in FishBASE.org } -\details{ -e.g. http://www.fishbase.us/Country -} \examples{ \dontshow{if (interactive() ) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -\dontrun{ c_code(440) -} \dontshow{\}) # examplesIf} } diff --git a/man/common_names.Rd b/man/common_names.Rd index a9d6b2f..fd879f1 100644 --- a/man/common_names.Rd +++ b/man/common_names.Rd @@ -7,9 +7,9 @@ \usage{ common_names( species_list = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, Language = "English", fields = NULL ) @@ -17,18 +17,15 @@ common_names( \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} \item{Language}{a string specifying the language for the common name, e.g. "English"} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} } \value{ a data.frame of common names by species queried. If multiple species are queried, @@ -38,5 +35,10 @@ The resulting data.frames are concatenated. Return a table of common names } \details{ -Note that there are many common names for a given sci name, so sci_to_common doesn't make sense +Note that there are many common names for a given sci name +} +\examples{ +\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +common_names("Bolbometopon muricatum") +\dontshow{\}) # examplesIf} } diff --git a/man/common_to_sci.Rd b/man/common_to_sci.Rd index a2a604f..2cc2ef3 100644 --- a/man/common_to_sci.Rd +++ b/man/common_to_sci.Rd @@ -7,9 +7,9 @@ common_to_sci( x, Language = "English", - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db() + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL ) } \arguments{ @@ -17,13 +17,11 @@ common_to_sci( \item{Language}{a string specifying the language for the common name, e.g. "English"} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} } \value{ a character vector of scientific names @@ -45,5 +43,5 @@ common_to_sci(c("Coho Salmon", "trout")) \dontshow{\}) # examplesIf} } \seealso{ -\code{\link{species_list}}, \code{\link{synonyms}} +\code{\link{synonyms}} } diff --git a/man/country.Rd b/man/country.Rd index e61b8fa..fc58895 100644 --- a/man/country.Rd +++ b/man/country.Rd @@ -7,38 +7,32 @@ country( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \description{ return a table of country for the requested species, as reported in FishBASE.org } -\details{ -e.g. http://www.fishbase.us/Country -} \examples{ \dontshow{if (interactive() ) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} \dontrun{ -country(species_list(Genus='Labroides')) +country("Bolbometopon muricatum") } \dontshow{\}) # examplesIf} } diff --git a/man/countrysub.Rd b/man/countrysub.Rd index 3a88667..f188927 100644 --- a/man/countrysub.Rd +++ b/man/countrysub.Rd @@ -7,27 +7,24 @@ countrysub( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \description{ return a table of countrysub for the requested species diff --git a/man/countrysubref.Rd b/man/countrysubref.Rd index b6b4020..6c0f91b 100644 --- a/man/countrysubref.Rd +++ b/man/countrysubref.Rd @@ -12,15 +12,13 @@ countrysubref( ) } \arguments{ -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \description{ return a table of countrysubref diff --git a/man/db_dir.Rd b/man/db_dir.Rd deleted file mode 100644 index caaff90..0000000 --- a/man/db_dir.Rd +++ /dev/null @@ -1,11 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/local_db.R -\name{db_dir} -\alias{db_dir} -\title{show fishbase directory} -\usage{ -db_dir() -} -\description{ -show fishbase directory -} diff --git a/man/db_disconnect.Rd b/man/db_disconnect.Rd deleted file mode 100644 index 6be7927..0000000 --- a/man/db_disconnect.Rd +++ /dev/null @@ -1,15 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/local_db.R -\name{db_disconnect} -\alias{db_disconnect} -\title{disconnect the database} -\usage{ -db_disconnect(db = NULL) -} -\arguments{ -\item{db}{optional, an existing pointer to the db, e.g. from [fb_conn()] -or [fb_import()].} -} -\description{ -disconnect the database -} diff --git a/man/diet.Rd b/man/diet.Rd index 1a101ef..dcbaaad 100644 --- a/man/diet.Rd +++ b/man/diet.Rd @@ -7,27 +7,24 @@ diet( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species diet diff --git a/man/distribution.Rd b/man/distribution.Rd deleted file mode 100644 index 0c54260..0000000 --- a/man/distribution.Rd +++ /dev/null @@ -1,45 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/distribution.R -\name{distribution} -\alias{distribution} -\title{distribution} -\usage{ -distribution( - species_list = NULL, - fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(), - ... -) -} -\arguments{ -\item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} - -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} - -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} - -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} - -\item{db}{the} - -\item{...}{unused; for backwards compatibility only} -} -\description{ -return a table of species locations as reported in FishBASE.org FAO location data -} -\details{ -currently this is ~ FAO areas table (minus "note" field) -e.g. http://www.fishbase.us/Country/FaoAreaList.php?ID=5537 -} -\examples{ -\dontshow{if (interactive() ) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -\dontrun{ -distribution(species_list(Genus='Labroides')) -} -\dontshow{\}) # examplesIf} -} diff --git a/man/docs.Rd b/man/docs.Rd deleted file mode 100644 index 25483cc..0000000 --- a/man/docs.Rd +++ /dev/null @@ -1,42 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/docs.R -\name{docs} -\alias{docs} -\title{docs} -\usage{ -docs(table = NULL, server = NULL, ...) -} -\arguments{ -\item{table}{the table for which the documentation should be displayed. If no table is given, -documentation summarizing all available tables is shown.} - -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} - -\item{...}{unused; for backwards compatibility only} -} -\value{ -A data.frame which lists the name of each table (if no table argument is given), along with a description -of the table and a URL linking to further information about the table. If a specific table is named in the -table argument, then the function will return a data.frame listing all the fields (columns) found in that table, -a description of what the field label means, and the units in which the field is measured. These descriptions of the -columns are not made available by FishBase and must be manually generated and curated by FishBase users. -At this time, many fields are still missing. Please take a moment to fill in any fields you use in the source -table here: https://github.com/ropensci/fishbaseapi/tree/master/docs/docs-sources -} -\description{ -documentation of tables and fields -} -\examples{ -\dontshow{if (interactive() ) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -\donttest{ -tables <- docs() -# Describe the fecundity table -dplyr::filter(tables, table == "fecundity")$description -## See fields in fecundity table -docs("fecundity") -## Note: only -} -\dontshow{\}) # examplesIf} -} diff --git a/man/ecology.Rd b/man/ecology.Rd index 2541ad1..90ff97d 100644 --- a/man/ecology.Rd +++ b/man/ecology.Rd @@ -7,27 +7,24 @@ ecology( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species ecology data diff --git a/man/ecosystem.Rd b/man/ecosystem.Rd index a6180c0..851c642 100644 --- a/man/ecosystem.Rd +++ b/man/ecosystem.Rd @@ -8,26 +8,23 @@ ecosystem( species_list = NULL, fields = NULL, server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species ecosystems data diff --git a/man/estimate.Rd b/man/estimate.Rd index 3314095..0a7a71e 100644 --- a/man/estimate.Rd +++ b/man/estimate.Rd @@ -7,27 +7,24 @@ estimate( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of estimates from some models on trophic levels diff --git a/man/faoareas.Rd b/man/faoareas.Rd index 8839637..cc040ff 100644 --- a/man/faoareas.Rd +++ b/man/faoareas.Rd @@ -8,26 +8,23 @@ faoareas( species_list = NULL, fields = NULL, server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a tibble, empty tibble if no results found @@ -35,14 +32,8 @@ a tibble, empty tibble if no results found \description{ return a table of species locations as reported in FishBASE.org FAO location data } -\details{ -currently this is ~ FAO areas table (minus "note" field) -e.g. http://www.fishbase.us/Country/FaoAreaList.php?ID=5537 -} \examples{ \dontshow{if (interactive() ) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -\dontrun{ faoareas() -} \dontshow{\}) # examplesIf} } diff --git a/man/fb_conn.Rd b/man/fb_conn.Rd deleted file mode 100644 index f30d1df..0000000 --- a/man/fb_conn.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/local_db.R -\name{fb_conn} -\alias{fb_conn} -\title{Cacheable database connection} -\usage{ -fb_conn(server = c("fishbase", "sealifebase"), version = "latest") -} -\arguments{ -\item{server}{fishbase or sealifebase} - -\item{version}{release version} -} -\description{ -Cacheable database connection -} diff --git a/man/fb_import.Rd b/man/fb_import.Rd deleted file mode 100644 index 47c5610..0000000 --- a/man/fb_import.Rd +++ /dev/null @@ -1,37 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/parquet_db.R -\name{fb_import} -\alias{fb_import} -\title{Import tables to local store} -\usage{ -fb_import( - server = c("fishbase", "sealifebase"), - version = get_latest_release(), - db = fb_conn(server, version), - tables = NULL -) -} -\arguments{ -\item{server}{fishbase or sealifebase} - -\item{version}{release version} - -\item{db}{A cachable duckdb database connection} - -\item{tables}{list of tables to import. Default `NULL` will -import all tables.} -} -\description{ -Import tables to local store -} -\details{ -Downloads and stores tables from the requested version of -fishbase or sealifebase. If the table is already downloaded, it will -not be re-downloaded. Imported tables are added to the active duckdb -connection. Note that there is no need to call this -} -\examples{ -\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -conn <- fb_import() -\dontshow{\}) # examplesIf} -} diff --git a/man/fb_tables.Rd b/man/fb_tables.Rd index 8fa7699..4ab4298 100644 --- a/man/fb_tables.Rd +++ b/man/fb_tables.Rd @@ -1,18 +1,24 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/parquet_db.R +% Please edit documentation in R/fb_tbl.R \name{fb_tables} \alias{fb_tables} -\title{fb_tables -list tables} +\title{List the tables available on fishbase/sealifebase} \usage{ fb_tables(server = c("fishbase", "sealifebase"), version = "latest") } \arguments{ -\item{server}{fishbase or sealifebase} +\item{server}{Access data from fishbase or sealifebase?} -\item{version}{release version} +\item{version}{Version, see [available_releases()]} } \description{ -fb_tables -list tables +These table names can be used to access each of the corresponding tables +using `[fb_tbl()]`. Please note that following RDB design, it is often +necessary to join multiple tables. Other data cleaning steps are sometimes +necessary as well. +} +\examples{ +\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +fb_tables() +\dontshow{\}) # examplesIf} } diff --git a/man/fb_tbl.Rd b/man/fb_tbl.Rd index 1d13a9d..1435822 100644 --- a/man/fb_tbl.Rd +++ b/man/fb_tbl.Rd @@ -8,7 +8,7 @@ fb_tbl( tbl, server = c("fishbase", "sealifebase"), version = "latest", - db = fb_conn(server, version), + db = NULL, collect = TRUE ) } @@ -16,18 +16,29 @@ fb_tbl( \item{tbl}{table name, as it appears in the database. See [fb_tables()] for a list.} -\item{server}{fishbase or sealifebase} +\item{server}{Access data from fishbase or sealifebase?} -\item{version}{release version} +\item{version}{Version, see [available_releases()]} -\item{db}{A cachable duckdb database connection} +\item{db}{database connection, deprecated} \item{collect}{should we return an in-memory table? Generally best to leave as TRUE unless RAM is too limited. A remote table can be used with most dplyr functions (filter, select, joins, etc) to further refine.} } \description{ -Access a fishbase or sealifebase table +Please note that rfishbase accesses static snapshots of the raw database +tables used by FishBase and Sealifebase websites. Because these are static +snapshots, they may lag behind the latest available information on the web +interface, but should provide stable results. +} +\details{ +Please also note that the website pages are not organized precisely along +the lines of these tables. A given page for a species may draw on data from +multiple tables, and sometimes presents the data in a processed or summarized +form. Following RDB design, it is often +necessary to join multiple tables. Other data cleaning steps are sometimes +necessary as well. } \examples{ \dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} diff --git a/man/fecundity.Rd b/man/fecundity.Rd index 8afd5c1..428de78 100644 --- a/man/fecundity.Rd +++ b/man/fecundity.Rd @@ -7,27 +7,24 @@ fecundity( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species fecundity diff --git a/man/fishbase_pane.Rd b/man/fishbase_pane.Rd deleted file mode 100644 index e018f5d..0000000 --- a/man/fishbase_pane.Rd +++ /dev/null @@ -1,18 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/rstudio_pane.R -\name{fishbase_pane} -\alias{fishbase_pane} -\title{Open database connection pane in RStudio} -\usage{ -fishbase_pane() -} -\description{ -This function launches the RStudio "Connection" pane to interactively -explore the database. -} -\examples{ -\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} - -if (!is.null(getOption("connectionObserver"))) fishbase_pane() -\dontshow{\}) # examplesIf} -} diff --git a/man/fooditems.Rd b/man/fooditems.Rd index d0bc9c4..9a484db 100644 --- a/man/fooditems.Rd +++ b/man/fooditems.Rd @@ -7,27 +7,24 @@ fooditems( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species fooditems diff --git a/man/genetics.Rd b/man/genetics.Rd index fba4de9..2bf5120 100644 --- a/man/genetics.Rd +++ b/man/genetics.Rd @@ -7,27 +7,24 @@ genetics( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species genetics data diff --git a/man/introductions.Rd b/man/introductions.Rd index 474814d..025ebc1 100644 --- a/man/introductions.Rd +++ b/man/introductions.Rd @@ -7,27 +7,24 @@ introductions( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species introductions data diff --git a/man/larvae.Rd b/man/larvae.Rd index c117446..119e591 100644 --- a/man/larvae.Rd +++ b/man/larvae.Rd @@ -7,27 +7,24 @@ larvae( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of larval data diff --git a/man/length_freq.Rd b/man/length_freq.Rd index a6b6546..63c94a3 100644 --- a/man/length_freq.Rd +++ b/man/length_freq.Rd @@ -8,27 +8,24 @@ length_freq( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of length_freq information by species; see details diff --git a/man/length_length.Rd b/man/length_length.Rd index b2e58c8..c4a5f09 100644 --- a/man/length_length.Rd +++ b/man/length_length.Rd @@ -8,27 +8,24 @@ length_length( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of lengths diff --git a/man/length_weight.Rd b/man/length_weight.Rd index d87c9ea..5bb8d04 100644 --- a/man/length_weight.Rd +++ b/man/length_weight.Rd @@ -8,27 +8,24 @@ length_weight( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of length_weight information by species; see details diff --git a/man/load_taxa.Rd b/man/load_taxa.Rd index 1f9b282..3f9dc82 100644 --- a/man/load_taxa.Rd +++ b/man/load_taxa.Rd @@ -4,25 +4,13 @@ \alias{load_taxa} \title{load_taxa} \usage{ -load_taxa( - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), - collect = TRUE, - ... -) +load_taxa(server = c("fishbase", "sealifebase"), version = "latest", ...) } \arguments{ \item{server}{Either "fishbase" (the default) or "sealifebase"} \item{version}{the version of the database you want. Will default to the -latest avialable; see [available_releases()].} - -\item{db}{A remote database connection. Will default to the best available -system, see [default_db()].} - -\item{collect}{return a data.frame if TRUE, otherwise, a DBI connection to -the table in the database} +latest available; see [available_releases()].} \item{...}{for compatibility with previous versions} } diff --git a/man/maturity.Rd b/man/maturity.Rd index de31164..f446104 100644 --- a/man/maturity.Rd +++ b/man/maturity.Rd @@ -7,27 +7,24 @@ maturity( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species maturity diff --git a/man/morphology.Rd b/man/morphology.Rd index 35ed913..0cafc0a 100644 --- a/man/morphology.Rd +++ b/man/morphology.Rd @@ -7,27 +7,24 @@ morphology( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species morphology data diff --git a/man/morphometrics.Rd b/man/morphometrics.Rd index 44dc54c..204c928 100644 --- a/man/morphometrics.Rd +++ b/man/morphometrics.Rd @@ -7,27 +7,24 @@ morphometrics( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species morphometrics data diff --git a/man/occurrence.Rd b/man/occurrence.Rd deleted file mode 100644 index d34f6b0..0000000 --- a/man/occurrence.Rd +++ /dev/null @@ -1,15 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/distribution.R -\name{occurrence} -\alias{occurrence} -\title{occurrence} -\usage{ -occurrence() -} -\description{ -occurrence -} -\details{ -THE OCCURRENCE TABLE HAS BEEN DROPPED BY FISHBASE - THIS -FUNCTION NOW RETURNS A STOP MESSAGE. -} diff --git a/man/oxygen.Rd b/man/oxygen.Rd index 7f6b412..1056a33 100644 --- a/man/oxygen.Rd +++ b/man/oxygen.Rd @@ -7,27 +7,24 @@ oxygen( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species oxygen data diff --git a/man/popchar.Rd b/man/popchar.Rd index faf8f96..350ab8a 100644 --- a/man/popchar.Rd +++ b/man/popchar.Rd @@ -7,27 +7,24 @@ popchar( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \description{ Table of maximum length (Lmax), weight (Wmax) and age (tmax) diff --git a/man/popgrowth.Rd b/man/popgrowth.Rd index cc2341a..02d6e83 100644 --- a/man/popgrowth.Rd +++ b/man/popgrowth.Rd @@ -7,27 +7,24 @@ popgrowth( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of population growth information by species; see details diff --git a/man/popqb.Rd b/man/popqb.Rd index 40e6e8c..568cf5a 100644 --- a/man/popqb.Rd +++ b/man/popqb.Rd @@ -7,27 +7,24 @@ popqb( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species popqb diff --git a/man/predators.Rd b/man/predators.Rd index abc9255..a9618b2 100644 --- a/man/predators.Rd +++ b/man/predators.Rd @@ -7,27 +7,24 @@ predators( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of predators diff --git a/man/ration.Rd b/man/ration.Rd index 8d7ac8a..3bd7ed4 100644 --- a/man/ration.Rd +++ b/man/ration.Rd @@ -7,27 +7,24 @@ ration( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species ration diff --git a/man/reexports.Rd b/man/reexports.Rd index 18d438d..8bb1f21 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fb_tbl.R +% Please edit documentation in R/00-endpoint.R \docType{import} \name{reexports} \alias{reexports} diff --git a/man/references.Rd b/man/references.Rd index 07ed1ca..a51b0a2 100644 --- a/man/references.Rd +++ b/man/references.Rd @@ -17,18 +17,15 @@ references( \item{codes}{One or more Fishbase reference numbers, matching the RefNo field} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a tibble (data.frame) of reference data diff --git a/man/reproduction.Rd b/man/reproduction.Rd index e116b43..032a085 100644 --- a/man/reproduction.Rd +++ b/man/reproduction.Rd @@ -7,27 +7,24 @@ reproduction( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species reproduction diff --git a/man/rfishbase-package.Rd b/man/rfishbase-package.Rd deleted file mode 100644 index 9ab38e6..0000000 --- a/man/rfishbase-package.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fishbase.R -\docType{package} -\name{rfishbase-package} -\alias{rfishbase-package} -\alias{rfishbase} -\title{The new R interface to Fishbase, v2.0} -\description{ -A programmatic interface to FishBase, re-written -based on an accompanying 'RESTful' API. Access tables describing over 30,000 -species of fish, their biology, ecology, morphology, and more. This package also -supports experimental access to SeaLifeBase data, which contains -nearly 200,000 species records for all types of aquatic life not covered by -FishBase.' -} -\author{ -Carl Boettiger \email{carl@ropensci.org} - -Scott Chamberlain \email{scott@ropensci.org} -} -\keyword{package} diff --git a/man/spawning.Rd b/man/spawning.Rd index b11e4f6..8d200c3 100644 --- a/man/spawning.Rd +++ b/man/spawning.Rd @@ -7,27 +7,24 @@ spawning( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species spawning diff --git a/man/species.Rd b/man/species.Rd index e4cdc13..b7d5777 100644 --- a/man/species.Rd +++ b/man/species.Rd @@ -2,33 +2,29 @@ % Please edit documentation in R/species.R \name{species} \alias{species} -\alias{species_info} \title{species} \usage{ species( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a data.frame with rows for species and columns for the fields returned by the query (FishBase 'species' table) @@ -47,7 +43,6 @@ Species scientific names are defined according to fishbase taxonomy and nomencla \dontrun{ species(c("Labroides bicolor", "Bolbometopon muricatum")) -species(c("Labroides bicolor", "Bolbometopon muricatum"), fields = species_fields$habitat) } } diff --git a/man/species_by_ecosystem.Rd b/man/species_by_ecosystem.Rd index c3c3db0..e5e0fcc 100644 --- a/man/species_by_ecosystem.Rd +++ b/man/species_by_ecosystem.Rd @@ -8,8 +8,8 @@ species_by_ecosystem( ecosystem, species_list = NULL, server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(), + version = "latest", + db = NULL, ... ) } @@ -18,15 +18,13 @@ species_by_ecosystem( \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species ecosystems data diff --git a/man/species_fields.Rd b/man/species_fields.Rd deleted file mode 100644 index 5c3765f..0000000 --- a/man/species_fields.Rd +++ /dev/null @@ -1,13 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/species.R -\docType{data} -\name{species_fields} -\alias{species_fields} -\title{A list of the species_fields available} -\description{ -A list of the species_fields available -} -\author{ -Carl Boettiger \email{carl@ropensci.org} -} -\keyword{data} diff --git a/man/species_list.Rd b/man/species_list.Rd deleted file mode 100644 index 0d35a27..0000000 --- a/man/species_list.Rd +++ /dev/null @@ -1,50 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/species_list.R -\name{species_list} -\alias{species_list} -\title{species_list} -\usage{ -species_list( - Class = NULL, - Order = NULL, - Family = NULL, - Subfamily = NULL, - Genus = NULL, - Species = NULL, - SpecCode = NULL, - SuperClass = NULL, - server = getOption("FISHBASE_API", FISHBASE_API) -) -} -\arguments{ -\item{Class}{Request all species in this taxonomic Class} - -\item{Order}{Request all species in this taxonomic Order} - -\item{Family}{Request all species in this taxonomic Family} - -\item{Subfamily}{Request all species in this taxonomic SubFamily} - -\item{Genus}{Request all species in this taxonomic Genus} - -\item{Species}{Request all species in this taxonomic Species} - -\item{SpecCode}{Request species name of species matching this SpecCode} - -\item{SuperClass}{Request all species of this Superclass} - -\item{server}{fishbase or sealifebase} -} -\description{ -Return the a species list given a taxonomic group -} -\examples{ -\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -\donttest{ -## All species in the Family - species_list(Family = 'Scaridae') -## All species in the Genus - species_list(Genus = 'Labroides') -} -\dontshow{\}) # examplesIf} -} diff --git a/man/species_names.Rd b/man/species_names.Rd deleted file mode 100644 index 2ddf0d6..0000000 --- a/man/species_names.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/species_names.R -\name{species_names} -\alias{species_names} -\title{species names} -\usage{ -species_names( - codes, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db() -) -} -\arguments{ -\item{codes}{a vector of speccodes (e.g. column from a table)} - -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} - -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} - -\item{db}{the} -} -\value{ -A character vector of species names for the SpecCodes -} -\description{ -returns species names given FishBase's SpecCodes -} diff --git a/man/speed.Rd b/man/speed.Rd index 57e0bfd..8060aa4 100644 --- a/man/speed.Rd +++ b/man/speed.Rd @@ -7,27 +7,24 @@ speed( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species speed data diff --git a/man/stocks.Rd b/man/stocks.Rd index c19fc04..78dba92 100644 --- a/man/stocks.Rd +++ b/man/stocks.Rd @@ -7,27 +7,24 @@ stocks( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species stocks data diff --git a/man/swimming.Rd b/man/swimming.Rd index 06de8c5..eaaad7b 100644 --- a/man/swimming.Rd +++ b/man/swimming.Rd @@ -7,27 +7,24 @@ swimming( species_list = NULL, fields = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(server, version), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{fields}{a character vector specifying which fields (columns) should be returned. By default, -all available columns recognized by the parser are returned. Mostly for backwards compatibility as users can subset by column later} +\item{fields}{subset to these columns. (recommend to omit this and handle manually)} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a table of species swimming data diff --git a/man/synonyms.Rd b/man/synonyms.Rd index 3a88154..9795617 100644 --- a/man/synonyms.Rd +++ b/man/synonyms.Rd @@ -6,24 +6,22 @@ \usage{ synonyms( species_list = NULL, - server = getOption("FISHBASE_API", "fishbase"), - version = get_latest_release(), - db = default_db(), + server = c("fishbase", "sealifebase"), + version = "latest", + db = NULL, ... ) } \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ A table with information about the synonym. Will generally be only a single diff --git a/man/validate_names.Rd b/man/validate_names.Rd index 319fbe7..5e744ea 100644 --- a/man/validate_names.Rd +++ b/man/validate_names.Rd @@ -15,15 +15,13 @@ validate_names( \arguments{ \item{species_list}{A vector of scientific names (each element as "genus species"). If empty, a table for all fish will be returned.} -\item{server}{can be set to either "fishbase" or "sealifebase" to switch between databases. NOTE: it is usually -easier to leave this as NULL and set the source instead using the environmental variable `FISHBASE_API`, e.g. -`Sys.setenv(FISHBASE_API="sealifebase")`.} +\item{server}{Either "fishbase" or "sealifebase".} -\item{version}{a version string for the database, will default to the latest release. see [get_releases()] for details.} +\item{version}{a version string for the database. See [available_releases()] for details.} -\item{db}{the} +\item{db}{database connection, now deprecated.} -\item{...}{unused; for backwards compatibility only} +\item{...}{additional arguments, currently ignored} } \value{ a string of the validated names diff --git a/tests/testthat/setup-test_db.R b/tests/testthat/setup-test_db.R deleted file mode 100644 index 44b9151..0000000 --- a/tests/testthat/setup-test_db.R +++ /dev/null @@ -1,6 +0,0 @@ - -#test_db <- file.path(tempdir(), "rfishbase") -#dir.create(test_db, showWarnings = FALSE) -#Sys.setenv(FISHBASE_HOME=test_db) -#options(rfishbase_local_prov=TRUE) -#options(rfishbase_local_db=TRUE) \ No newline at end of file diff --git a/tests/testthat/teardown-tests.R b/tests/testthat/teardown-tests.R deleted file mode 100644 index adb539c..0000000 --- a/tests/testthat/teardown-tests.R +++ /dev/null @@ -1,2 +0,0 @@ -unlink(db_dir(), recursive = TRUE, force = TRUE) - diff --git a/tests/testthat/test_distribution.R b/tests/testthat/test_distribution.R index 2dd65ab..760f147 100644 --- a/tests/testthat/test_distribution.R +++ b/tests/testthat/test_distribution.R @@ -8,10 +8,10 @@ test_that("We can query locations", { sp <- c("Labroides bicolor", "Labroides dimidiatus", "Labroides pectoralis", "Labroides phthirophagus", "Labroides rubrolabiatus") - df <- distribution(sp) + df <- faoareas(sp) expect_is(df, "data.frame") - df <- distribution() + df <- faoareas() expect_is(df, "data.frame") ## currently these are remote tables @@ -27,7 +27,6 @@ test_that("We can query locations", { df <- country_names() expect_is(df, "tbl") - expect_error(occurrence()) - + }) diff --git a/tests/testthat/test_endpoint.R b/tests/testthat/test_endpoint.R index bd055f0..e70d36f 100644 --- a/tests/testthat/test_endpoint.R +++ b/tests/testthat/test_endpoint.R @@ -19,8 +19,6 @@ test_that("Custom queries give desired result", { expect_is(rr, "tbl") expect_equal(nrow(rr), 2) - df <- species_names(2) - expect_is(df, "tbl") }) diff --git a/tests/testthat/test_species.R b/tests/testthat/test_species.R index 56864c2..cc0d2c3 100644 --- a/tests/testthat/test_species.R +++ b/tests/testthat/test_species.R @@ -16,28 +16,6 @@ test_that("Check some classes and values of species table", { }) -test_that("We can pass a species_list based on taxanomic group", { - - needs_api() - fish <- species_list(Genus = "Labroides") - df <- species(fish) - expect_is(df, "data.frame") - expect_gt(dim(df)[1], 0) - - -}) - -test_that("We can pass a species_list based on taxanomic group", { - - needs_api() - fish <- species_list(Genus = "Labroides") - df <- species(fish) - expect_is(df, "data.frame") - expect_gt(dim(df)[1], 0) - - -}) - ## Test filters test_that("We can filter on certain fields",{ needs_api() @@ -46,7 +24,5 @@ test_that("We can filter on certain fields",{ expect_is(df, "data.frame") expect_gt(dim(df)[1], 0) - df <- load_species_meta() - }) diff --git a/tests/testthat/test_species_list.R b/tests/testthat/test_species_list.R deleted file mode 100644 index 36caf71..0000000 --- a/tests/testthat/test_species_list.R +++ /dev/null @@ -1,25 +0,0 @@ -context("species list") - -test_that("We can pass a species_list based on taxanomic group", { - - needs_api() - fish <- species_list(Genus = "Labroides") - expect_is(fish, "character") - expect_gt(length(fish), 1) - -}) - -test_that("Look up species by SpecCode", { - - needs_api() - - fish <- species_list(SpecCode = "5537") - expect_is(fish, "character") - expect_equal(fish, "Bolbometopon muricatum") - -}) - - -# Tests wrt caching - -# Test with alternate queries?