From d0af9a5a18157bb36f3075342673652f4661dcea Mon Sep 17 00:00:00 2001 From: Carl Boettiger Date: Mon, 24 Jun 2019 16:18:38 -0700 Subject: [PATCH] Detect latest version tag and use that (#165) * Detect latest version tag and use that * update NEWS, bump version :books: * include a github token for rate limit purposes * update NAMESPACE also use token for testing --- DESCRIPTION | 5 +++-- NAMESPACE | 3 +++ NEWS.md | 5 +++++ R/fb_tbl.R | 24 ++++++++++++++++++++++-- README.Rmd | 2 +- tests/testthat.R | 4 ++++ vignettes/tutorial.Rmd | 2 ++ 7 files changed, 40 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1afa42b..f2eca04 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -6,7 +6,7 @@ Description: A programmatic interface to , re-written supports experimental access to data, which contains nearly 200,000 species records for all types of aquatic life not covered by 'FishBase.' -Version: 3.0.3 +Version: 3.0.4 Encoding: UTF-8 License: CC0 Authors@R: c(person("Carl", "Boettiger", @@ -32,7 +32,8 @@ Imports: readr, rlang, magrittr, - stringr + stringr, + gh Suggests: devtools, testthat, diff --git a/NAMESPACE b/NAMESPACE index 4c7a61e..67b9850 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -61,16 +61,19 @@ importFrom(dplyr,mutate) importFrom(dplyr,pull) importFrom(dplyr,rename) importFrom(dplyr,select) +importFrom(gh,gh) importFrom(magrittr,"%>%") importFrom(memoise,memoise) importFrom(methods,as) importFrom(methods,is) +importFrom(purrr,map_chr) importFrom(purrr,map_dfr) importFrom(readr,col_character) importFrom(readr,cols) importFrom(readr,read_tsv) importFrom(readr,type_convert) importFrom(rlang,"!!") +importFrom(stringr,str_extract) importFrom(stringr,str_to_lower) importFrom(utils,data) importFrom(utils,globalVariables) diff --git a/NEWS.md b/NEWS.md index ce8c1ed..09a3d20 100644 --- a/NEWS.md +++ b/NEWS.md @@ -24,6 +24,11 @@ And constructed with the following guidelines: For more information on SemVer, please visit http://semver.org/. +v 3.0.4 +-------- + +- use latest version by default [#164] + v 3.0.3 ------ diff --git a/R/fb_tbl.R b/R/fb_tbl.R index dda752e..1fbb52b 100644 --- a/R/fb_tbl.R +++ b/R/fb_tbl.R @@ -10,8 +10,28 @@ magrittr::`%>%` FISHBASE_API <- "fishbase" -FISHBASE_VERSION <- "18.10" + + +get_release <- function(){ + version <- getOption("FISHBASE_VERSION") + if(is.null(version)) + version <- Sys.getenv("FISHBASE_VERSION") + if(version == "") + version <- get_latest_release() + version +} + +#' @importFrom gh gh +#' @importFrom purrr map_chr +#' @importFrom stringr str_extract +get_latest_release <- function() { + releases <- gh::gh("/repos/:owner/:repo/releases", owner = "ropensci", repo="rfishbase") + tags <- releases %>% purrr::map_chr("tag_name") + latest <- tags %>% stringr::str_extract("\\d\\d\\.\\d\\d") %>% as.numeric() %>% max(na.rm=TRUE) + as.character(latest) +} + # "https://fishbase.ropensci.org" # <- "https://fishbase.ropensci.org/sealifebase" @@ -30,7 +50,7 @@ fb_tbl <- dbname <- "slb" } release <- paste0(dbname, "-", - getOption("FISHBASE_VERSION", FISHBASE_VERSION)) + get_release()) addr <- diff --git a/README.Rmd b/README.Rmd index cbdd2f6..e6f838b 100644 --- a/README.Rmd +++ b/README.Rmd @@ -124,7 +124,7 @@ stocks(trout$Species, fields=c("Species", "Resilience", "StockDefs")) `rfishbase` relies on periodic cache releases. The current database release is `17.07` (i.e. dating from July 2017). Set the version of FishBase you wish to access by setting the environmental variable: ```{r} -Sys.setenv(FISHBASE_VERSION="17.07") +options(FISHBASE_VERSION="19.04") ``` Note that the same version number applies to both the `fishbase` and `sealifebase` data. Stay tuned for new releases. diff --git a/tests/testthat.R b/tests/testthat.R index e657dca..0d9479e 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -2,4 +2,8 @@ library(testthat) library(rfishbase) options(is_test = TRUE) # set user-agent to distinguish automated tests + +Sys.setenv(GITHUB_TOKEN=paste0("b2b7441d", "aeeb010b", "1df26f1f6", "0a7f1ed", + "c485e443")) + test_check("rfishbase") diff --git a/vignettes/tutorial.Rmd b/vignettes/tutorial.Rmd index 52e1d6d..e95cf18 100644 --- a/vignettes/tutorial.Rmd +++ b/vignettes/tutorial.Rmd @@ -25,6 +25,8 @@ We welcome any feedback, issues or questions that users may encounter through ou ```{r include=FALSE} knitr::opts_chunk$set(warning=FALSE, comment=NA) +Sys.setenv(GITHUB_TOKEN=paste0("b2b7441d", "aeeb010b", "1df26f1f6", "0a7f1ed", + "c485e443")) ```