Skip to content

Commit 8e10277

Browse files
2nd CRAN submission
I have made extract_taxonomy online tests be skipped on CRAN and have made the tests print more information when they do fail, as suggested by Duncan Murdoch.
1 parent d7b4183 commit 8e10277

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

cran-comments.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,17 @@ only NOTE: This is a new submission.
1212

1313
## Downstream dependencies
1414

15-
There are currently no downstream dependencies for this package
15+
There are currently no downstream dependencies for this package
16+
17+
## Resubmissions
18+
19+
### Downloading test failures for `extract_taxonomy`
20+
21+
This happended last time on one CRAN test computer:
22+
23+
> test_check("metacoder")
24+
1. Failure: Exracting by obs_id works (@test--extract_taxonomy.R#27) -----------
25+
"Eukaryota" %in% result$taxon_data$name isn't true.
26+
27+
I think this is a rare error caused by the NCBI API.
28+
I have made these types of tests be skipped on CRAN and have made the tests print more information when they do fail, as suggested by Duncan Murdoch.

tests/testthat/Rplots.pdf

3.74 KB
Binary file not shown.

tests/testthat/test--extract_taxonomy.R

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,27 @@ test_data = c("obs_id: FJ712037.1 - name: Panthera leo - taxon_id: 9689 - class_
1313
test_regex <- "obs_id: (.*) - name: (.*) - taxon_id: (.*) - class_name: (.*) - class_id: (.*)"
1414

1515
check_for_internet <- function() {
16-
if (! is.character(RCurl::getURL("www.google.com"))) {
16+
result <- tryCatch(RCurl::getURL("www.google.com"), error = function(e) FALSE)
17+
if (! is.character(result)) {
1718
skip("Internet not available")
1819
}
1920
}
2021

22+
print_on_error <- function(result) {
23+
paste0(c("---- RESULT ----", capture.output(str(result))), collapse = "\n")
24+
}
25+
2126
#|
2227
#| ### Exracting by obs_id
2328
test_that("Exracting by obs_id works", {
29+
skip_on_cran()
2430
check_for_internet()
2531
result <- extract_taxonomy(test_data, key = "obs_id", regex = "obs_id: (.*?) -", database = "ncbi")
2632
expect_s3_class(result, "taxmap")
27-
expect_true("Eukaryota" %in% result$taxon_data$name)
33+
expect_true("Eukaryota" %in% result$taxon_data$name, info = print_on_error(result))
2834
})
2935
test_that("Invalid IDs cause understandable errors", {
36+
skip_on_cran()
3037
check_for_internet()
3138
expect_error(extract_taxonomy(c("FJ712037.1", "notvalid", "HW243304.1"),
3239
key = "obs_id", regex = "(.*)", database = "ncbi",
@@ -40,9 +47,10 @@ test_that("Exracting by classification names works", {
4047
result <- extract_taxonomy(test_data, key = "class", regex = "class_name: (.*?) -",
4148
class_key = "name", class_regex = "(.*)", class_sep = ";")
4249
expect_s3_class(result, "taxmap")
43-
expect_true("Caniformia" %in% result$taxon_data$name)
50+
expect_true("Caniformia" %in% result$taxon_data$name, info = print_on_error(result))
4451
})
4552
test_that("Looking up IDs for classification names works", {
53+
skip_on_cran()
4654
check_for_internet()
4755
result <- extract_taxonomy(c("Ascomycota_sp|AY773457|SH189849.06FU|reps|k__Fungi;p__Ascomycota;c__unidentified;o__unidentified;f__unidentified;g__unidentified;s__Ascomycota_sp",
4856
"Myrmecridium_schulzeri|EU041774|SH189850.06FU|reps|k__Fungi;p__Ascomycota;c__Sordariomycetes;o__Incertae_sedis;f__Incertae_sedis;g__Myrmecridium;s__Myrmecridium_schulzeri",
@@ -55,7 +63,7 @@ test_that("Looking up IDs for classification names works", {
5563
class_sep = ";",
5664
database = "ncbi")
5765
expect_s3_class(result, "taxmap")
58-
expect_equal(result$taxon_data$ncbi_id[1], "4751")
66+
expect_equal(result$taxon_data$ncbi_id[1], "4751", info = print_on_error(result))
5967
})
6068

6169

@@ -67,25 +75,27 @@ test_that("Exracting by classification IDs works", {
6775
result <- extract_taxonomy(test_data, key = "class", regex = "class_id: (.*?)$",
6876
class_key = "taxon_id", class_regex = "(.*)", class_sep = ";")
6977
expect_s3_class(result, "taxmap")
70-
expect_true("379583" %in% result$taxon_data$taxon_id)
78+
expect_true("379583" %in% result$taxon_data$taxon_id, info = print_on_error(result))
7179
})
7280

7381
#|
7482
#| ### Exracting by taxon name
7583
test_that("Exracting by taxon name works", {
84+
skip_on_cran()
7685
check_for_internet()
7786
result <- extract_taxonomy(test_data, key = "name", regex = "name: (.*?) - ", database = "ncbi")
7887
expect_s3_class(result, "taxmap")
79-
expect_true("379583" %in% result$taxon_data$ncbi_id)
88+
expect_true("379583" %in% result$taxon_data$ncbi_id, info = print_on_error(result))
8089
})
8190

8291
#|
8392
#| ### Exracting by taxon ID
8493
test_that("Exracting by taxon ID works", {
94+
skip_on_cran()
8595
check_for_internet()
8696
result <- extract_taxonomy(test_data, key = "taxon_id", regex = "taxon_id: (.*?) - ", database = "ncbi")
8797
expect_s3_class(result, "taxmap")
88-
expect_true("Eukaryota" %in% result$taxon_data$name)
98+
expect_true("Eukaryota" %in% result$taxon_data$name, info = print_on_error(result))
8999
})
90100

91101
#|

0 commit comments

Comments
 (0)