Skip to content

Commit

Permalink
Merge pull request #147 from trias-project/Fix-86
Browse files Browse the repository at this point in the history
Fix 86
  • Loading branch information
damianooldoni authored Nov 14, 2024
2 parents 7e0f1fb + 52594d3 commit 664ae14
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ rsconnect/

# Mac OS X
.DS_Store

# pdfs created by testing plots
/tests/testthat/*.pdf
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: trias
Title: Process Data for the Project Tracking Invasive Alien Species
(TrIAS)
Version: 3.0.0
Version: 3.0.1
Authors@R: c(
person("Damiano", "Oldoni", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-3445-7562")),
Expand Down
6 changes: 0 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export(climate_match)
export(gbif_get_taxa)
export(gbif_has_distribution)
export(gbif_verify_keys)
export(get_cred)
export(get_table_pathways)
export(indicator_introduction_year)
export(indicator_native_range_year)
Expand All @@ -20,12 +19,7 @@ export(visualize_pathways_year_level1)
export(visualize_pathways_year_level2)
importFrom(dplyr,"%>%")
importFrom(dplyr,.data)
importFrom(readr,read_tsv)
importFrom(readr,write_tsv)
importFrom(rgbif,occ_download_meta)
importFrom(rlang,"!!!")
importFrom(rlang,"!!")
importFrom(rlang,":=")
importFrom(rlang,sym)
importFrom(stringr,str_c)
importFrom(svDialogs,dlgInput)
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# trias 3.0.1

- Function `get_cred()` is not exported anymore (#146). Internally used only.

# trias 3.0.0

- Allow to specify x-scale stepsize for `indicator_native_range_year()` (#143)
Expand Down
2 changes: 1 addition & 1 deletion R/climate_match.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ climate_match <- function(region,
"countryCode"
)) %>%
dplyr::filter(.data$acceptedTaxonKey %in% taxon_key)
}else{
} else {
gbif_user <- get_cred("gbif_user")
gbif_pwd <- get_cred("gbif_pwd")
gbif_email <- get_cred("gbif_email")
Expand Down
13 changes: 7 additions & 6 deletions R/get_cred.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#' Interactively get & store credentials in the system environment
#'
#' @param x a character with the name of the system environment variable to get
#' and store
#' @return a character vector containing the value of the system variable
#' @export
#' @importFrom svDialogs dlgInput
#' @param x character. Name of the system environment variable to get
#' and store.
#'
#' @return character. Vector containing the value(s) of the system variable.
#'
#' @noRd
get_cred <- function(x) {
cred <- Sys.getenv(x)

if (cred == "") {
input <- dlgInput(paste0("What is your ", x, "?"))
input <- svDialogs::dlgInput(paste0("What is your ", x, "?"))
cred <- input$res
do.call(Sys.setenv, as.list(purrr::set_names(cred, x)))
}
Expand Down
17 changes: 7 additions & 10 deletions R/update_download_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,21 @@
#' @return message with the performed updates
#'
#' @export
#' @importFrom rgbif occ_download_meta
#' @importFrom readr read_tsv write_tsv
#' @importFrom stringr str_c
update_download_list <- function(file, download_to_add, input_checklist,
url_doi_base = "https://doi.org/") {
downloads <- read_tsv(file,
downloads <- readr::read_tsv(file,
trim_ws = TRUE,
na = "",
lazy = FALSE
)
# downloadKey not present
if (is.element(download_to_add, downloads$gbif_download_key) == FALSE) {
metadata <- occ_download_meta(key = download_to_add)
metadata <- rgbif::occ_download_meta(key = download_to_add)
gbif_download_status <- metadata$status
gbif_download_doi <- str_c(url_doi_base, metadata$doi)
gbif_download_doi <- stringr::str_c(url_doi_base, metadata$doi)
print(gbif_download_doi)
gbif_download_created <- metadata$created
write_tsv(
readr::write_tsv(
x = as.data.frame(list(
gbif_download_key = toString(download_to_add),
input_checklist = input_checklist,
Expand All @@ -64,15 +61,15 @@ update_download_list <- function(file, download_to_add, input_checklist,
"added to", file, "; download status =", gbif_download_status
))
# reload file
downloads <- read_tsv(file, na = "", lazy = FALSE)
downloads <- readr::read_tsv(file, na = "", lazy = FALSE)
} else {
print(paste("gbif_download_Key", download_to_add, "already present in", file))
}
# check all downloads with status "PREPARING" or "RUNNING".
changes <- FALSE
for (i in 1:nrow(downloads)) {
if (downloads$gbif_download_status[i] %in% c("RUNNING", "PREPARING")) {
metadata <- occ_download_meta(key = downloads$gbif_download_key[i])
metadata <- rgbif::occ_download_meta(key = downloads$gbif_download_key[i])
gbif_download_status <- metadata$status
# status is SUCCEEDED or FAILED
if (gbif_download_status %in% c("SUCCEEDED", "FAILED")) {
Expand All @@ -93,7 +90,7 @@ update_download_list <- function(file, download_to_add, input_checklist,
if (!changes) {
print("No changes in download status detected")
} else {
write_tsv(
readr::write_tsv(
x = downloads,
file = file,
na = "",
Expand Down
18 changes: 0 additions & 18 deletions man/get_cred.Rd

This file was deleted.

1 change: 0 additions & 1 deletion tests/testthat/test-output_gbif_get_taxa.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#' @importFrom readr read_tsv
context("output_gbif_get_taxa")


Expand Down

0 comments on commit 664ae14

Please sign in to comment.