Skip to content

Commit 7dcc74a

Browse files
committed
Fix #183
1 parent f7fe57b commit 7dcc74a

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: trias
22
Title: Process Data for the Project Tracking Invasive Alien Species
33
(TrIAS)
4-
Version: 3.2.2
4+
Version: 3.2.3
55
Authors@R: c(
66
person("Damiano", "Oldoni", , "damiano.oldoni@inbo.be", role = c("aut", "cre"),
77
comment = c(ORCID = "0000-0003-3445-7562")),

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# trias 3.2.3
2+
3+
- Fix a bug in `update_download_list()`. The fix ensures that the function can handle cases where there are no existing downloads without throwing an error (#183).
4+
15
# trias 3.2.2
26

3-
- Fix y-axis ticks values in `visualize_pathways_level1()` and `visualize_pathways_level2()` plots.
7+
- Fix y-axis ticks values in `visualize_pathways_level1()` and `visualize_pathways_level2()` plots (#181).
48

59
# trias 3.2.1
610

R/update_download_list.R

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@
3131
#' @export
3232
update_download_list <- function(file, download_to_add, input_checklist,
3333
url_doi_base = "https://doi.org/") {
34+
# `file` must have the right columns
35+
expected_columns <- c(
36+
"gbif_download_key",
37+
"input_checklist",
38+
"gbif_download_created",
39+
"gbif_download_status",
40+
"gbif_download_doi"
41+
)
42+
assertthat::assert_that(
43+
all(expected_columns %in% colnames(readr::read_tsv(file, n_max = 0))),
44+
msg = paste(
45+
"The file should contain the following columns:",
46+
paste(expected_columns, collapse = ", ")
47+
)
48+
)
3449
downloads <- readr::read_tsv(file,
3550
trim_ws = TRUE,
3651
na = "",
@@ -66,7 +81,6 @@ update_download_list <- function(file, download_to_add, input_checklist,
6681
} else {
6782
print(paste("gbif_download_Key", download_to_add, "already present in", file))
6883
}
69-
# check all downloads with status "PREPARING" or "RUNNING".
7084
changes <- FALSE
7185
for (i in 1:nrow(downloads)) {
7286
if (downloads$gbif_download_status[i] %in% c("RUNNING", "PREPARING")) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gbif_download_key input_checklist gbif_download_created gbif_download_status gbif_download_doi

tests/testthat/test-update_download_list.R

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
testthat::test_that("Error returned if file does not contain the right columns", {
2+
directory_data <- "./data_test_upload_list/"
3+
gbif_downloads_filename <- "gbif_downloads_wrong_cols.tsv"
4+
gbif_downloads_file <- paste0(directory_data, gbif_downloads_filename)
5+
gbif_download_key_to_add <- "0003300-181003121212138"
6+
checklist <- "https://raw.githubusercontent.com/trias-project/pipeline/9f20d33a14696bc42d059a2e0f50fb11c4f97d35/data/input/occ_indicator_emerging_species.tsv"
7+
testthat::expect_error(
8+
update_download_list(
9+
file = gbif_downloads_file,
10+
download_to_add = gbif_download_key_to_add,
11+
input_checklist = checklist
12+
),
13+
regexp = "The file should contain the following columns: gbif_download_key, input_checklist, gbif_download_created, gbif_download_status, gbif_download_doi"
14+
)
15+
})
16+
117
testthat::test_that("gbif download added correctly to list GBIF downloads and other status updated", {
2-
skip_on_os(os = "windows")
3-
#' define file containing gbif downloads
18+
# Define file containing gbif downloads
419
directory_data <- "./data_test_upload_list/"
520
gbif_downloads_filename <- "gbif_downloads.tsv"
621
gbif_downloads_file <- paste0(directory_data, gbif_downloads_filename)
722

8-
#' make a coy of it to replace original file at the end of the test
23+
# Make a coy of it to replace original file at the end of the test
924
gbif_downloads_filename_copy <- "gbif_downloads_copy.tsv"
1025
copy_file <- paste0(directory_data, gbif_downloads_filename_copy)
1126
file.copy(
@@ -18,12 +33,12 @@ testthat::test_that("gbif download added correctly to list GBIF downloads and ot
1833
na = "",
1934
lazy = FALSE)
2035

21-
#' define arguments related to new GBIF download
36+
# Define arguments related to new GBIF download
2237
gbif_download_key_to_add <- "0003300-181003121212138"
2338
checklist <- "https://raw.githubusercontent.com/trias-project/pipeline/9f20d33a14696bc42d059a2e0f50fb11c4f97d35/data/input/occ_indicator_emerging_species.tsv"
2439

2540

26-
#' apply update_download_list
41+
# Apply update_download_list
2742
update_download_list(
2843
file = gbif_downloads_file,
2944
download_to_add = gbif_download_key_to_add,

0 commit comments

Comments
 (0)