Skip to content

Commit

Permalink
Detect latest version tag and use that (#165)
Browse files Browse the repository at this point in the history
* Detect latest version tag and use that

* update NEWS, bump version 📚

* include a github token for rate limit purposes

* update NAMESPACE

also use token for testing
  • Loading branch information
cboettig committed Jun 24, 2019
1 parent 5709be7 commit d0af9a5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Expand Up @@ -6,7 +6,7 @@ Description: A programmatic interface to <http://www.fishbase.org>, re-written
supports experimental access to <http://www.sealifebase.org> 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",
Expand All @@ -32,7 +32,8 @@ Imports:
readr,
rlang,
magrittr,
stringr
stringr,
gh
Suggests:
devtools,
testthat,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Expand Up @@ -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
------

Expand Down
24 changes: 22 additions & 2 deletions R/fb_tbl.R
Expand Up @@ -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"

Expand All @@ -30,7 +50,7 @@ fb_tbl <-
dbname <- "slb"
}
release <- paste0(dbname, "-",
getOption("FISHBASE_VERSION", FISHBASE_VERSION))
get_release())


addr <-
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat.R
Expand Up @@ -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")
2 changes: 2 additions & 0 deletions vignettes/tutorial.Rmd
Expand Up @@ -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"))
```


Expand Down

0 comments on commit d0af9a5

Please sign in to comment.