Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A function to retrieve Github Releases of taxonomic resources #247

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
^CRAN-SUBMISSION$
^revdep
^.DS_Store
^inst/cheatsheet$
^help

1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(create_species_state_origin_matrix)
export(create_taxonomic_update_lookup)
export(default_version)
export(get_apc_genus_family_lookup)
export(get_versions)
export(load_taxonomic_resources)
export(native_anywhere_in_australia)
export(standardise_names)
Expand Down
3 changes: 2 additions & 1 deletion R/APCalign-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ utils::globalVariables(
"accepted_name_2",
"alternative_accepted_name_tmp",
"pro_parte",
"suggested_collapsed_name"
"suggested_collapsed_name",
"versions"
)
)

46 changes: 44 additions & 2 deletions R/load_taxonomic_resources.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' @examples
#' \donttest{
#' load_taxonomic_resources(stable_or_current_data="stable",
#' version="0.0.2.9000")}
#' version="2024-10-11")}
#'

load_taxonomic_resources <-
Expand Down Expand Up @@ -302,7 +302,7 @@ load_taxonomic_resources <-
##'
##'
##' # Load the a stable version of the dataset
##' dataset_access_function(version="0.0.2.9000",type = "stable")
##' dataset_access_function(version="2024-10-11",type = "stable")
##'
##' @noRd
dataset_access_function <-
Expand Down Expand Up @@ -487,3 +487,45 @@ dataset_get <- function(version = default_version(),

}
}


#' Which versions of taxonomic resources are available?
#'
#' @return tibble of dates when APC/APNI resources were downloaded as a Github Release
#' @export
#'
#' @examples
#' get_versions()
get_versions <- function() {
# Check if there is internet connection
## Dummy variable to allow testing of network
network <- as.logical(Sys.getenv("NETWORK_UP", unset = TRUE))

if (!curl::has_internet() | !network) { # Simulate if network is down
message("No internet connection, please retry with stable connection (default_version)")
return(invisible(NULL))
} else {

# Get all the releases
url <-
paste0(
"https://api.github.com/repos/",
"traitecoevo",
"/",
"APCalign",
"/releases"
)

response <- httr::GET(url)

if(httr::http_error(response) | !network){
message("API currently down, try again later")
return(invisible(NULL))
} else
release_data <- httr::content(response, "text") |> jsonlite::fromJSON()

# Create table
dplyr::tibble(versions = unique(release_data$tag_name) |> sort(decreasing = TRUE)) |>
dplyr::filter(!versions == "2020-05-14")
}
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ reference:
- subtitle: Data
- contents:
- load_taxonomic_resources
- get_versions
- default_version
- gbif_lite
17 changes: 17 additions & 0 deletions man/get_versions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/load_taxonomic_resources.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
if(exists("resources", envir = globalenv())) {
resources <- get("resources", envir = globalenv())
} else {
resources <- load_taxonomic_resources(stable_or_current_data = "stable", version = "0.0.2.9000")
resources <- load_taxonomic_resources(stable_or_current_data = "stable", version = "2024-10-11")
}
10 changes: 5 additions & 5 deletions tests/testthat/test-connection.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
test_that("Complains when network is down", {
skip_if_offline(host = "api.github.com")
skip_on_ci()

Sys.setenv("NETWORK_UP" = FALSE)
expect_message(default_version())
expect_message(dataset_access_function())
expect_message(dataset_get())

#commenting out for now to test in CI, see issue #235
#Sys.setenv("NETWORK_UP" = TRUE)
#expect_visible(default_version())
#expect_visible(dataset_access_function())
#expect_visible(dataset_get())
Sys.setenv("NETWORK_UP" = TRUE)
expect_visible(default_version())
expect_visible(dataset_access_function())
expect_visible(dataset_get())
})


10 changes: 10 additions & 0 deletions tests/testthat/test-versions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test_that("Retrieval is possible", {
skip_on_ci()

Sys.setenv("NETWORK_UP" = TRUE)
versions <- get_versions()

expect_visible(versions)
expect_named(versions)
})

Loading