Skip to content

Commit 74b1d5e

Browse files
committed
fix(get_functions): handle NULL/Na data in functions and unit tests
1 parent 4242a8f commit 74b1d5e

4 files changed

Lines changed: 8 additions & 3 deletions

File tree

R/get_species_itis.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
get_species_itis <- function(itis = NULL, stock = NULL) {
2828
# Error check for metric names
2929
if (is.null(itis) & is.null(stock)) {
30-
stop(
30+
return(
3131
"If you do not know the ITIS code then please enter a value for the
3232
`stock` argument. A character string of any part of the stock name.
3333
eg stock = \"Albacore\", stock = \"Cape Cod\""

R/get_species_stock_data.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
get_species_stock_data <- function(itis = NULL, stock = NULL) {
1919
# extract the stock ids since that is what is needed for the API
2020
meta <- get_species_itis(itis = itis, stock = stock)
21+
if (is.character(meta)) {
22+
return(meta)
23+
}
2124
user_stockids <- meta$StockID
2225

2326
# Start pull query

tests/testthat/test-get_species_itis.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ test_that("get_species_itis with specific itis", {
4747

4848
# test null both argument
4949
test_that("get_species_itis with null itis and stock", {
50-
expect_error(get_species_itis())
50+
res <- get_species_itis()
51+
expect_true(is.character(res))
5152
})

tests/testthat/test-get_species_stock_data.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ test_that("get_species_stock_data with itis as numeric, stock is null", {
4343

4444
# test null both argument
4545
test_that("get_species_stock_data with null itis and stock", {
46-
expect_error(get_species_stock_data())
46+
res <- get_species_stock_data()
47+
expect_true(is.character(res))
4748
})

0 commit comments

Comments
 (0)