Skip to content

Commit

Permalink
add attribution test
Browse files Browse the repository at this point in the history
  • Loading branch information
LewisAJones committed Mar 12, 2024
1 parent 02c78d1 commit d9707e2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 7 deletions.
13 changes: 9 additions & 4 deletions R/pick_phylopic.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ utils::globalVariables(c("x", "y", "uuid", "label"))
#' @param auto \code{numeric}. This argument allows the user to automate input
#' into the menu choice. If the input value is `1`, the first returned image
#' will be selected. If the input value is `2`, requested images will be
#' automatically cycled through with the final image returned. If `NULL`
#' (default), the user must interactively respond to the called menu.
#' automatically cycled through with the final image returned. If the input
#' value is `3`, a list of attribution information for each image is
#' returned (this functionality is principally intended for testing). If
#' `NULL` (default), the user must interactively respond to the called menu.
#'
#' @return A [Picture][grImport2::Picture-class] object is returned. The uuid of
#' the selected image is saved as the "uuid" attribute of the returned object
Expand Down Expand Up @@ -60,8 +62,8 @@ utils::globalVariables(c("x", "y", "uuid", "label"))
pick_phylopic <- function(name = NULL, n = 5, uuid = NULL, view = 1,
filter = NULL, auto = NULL) {
# Error handling
if (!is.null(auto) && !auto %in% c(1, 2)) {
stop("`auto` must be of value: NULL, 1, or 2")
if (!is.null(auto) && !auto %in% c(1, 2, 3)) {
stop("`auto` must be of value: NULL, 1, 2, or 3")
}
if (!is.numeric(view)) {
stop("`view` must be of class numeric.")
Expand Down Expand Up @@ -177,6 +179,9 @@ pick_phylopic <- function(name = NULL, n = 5, uuid = NULL, view = 1,
m <- n_plotted + 1
} else if (auto == 1) {
m <- 1
} else if (auto == 3) {
names(att) <- sapply(att, function(x) x$image_uuid)
return(att)
}
}

Expand Down
6 changes: 4 additions & 2 deletions man/pick_phylopic.Rd

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions tests/testthat/test-pick_phylo.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ test_that("pick_phylopic works", {
expect_true(is(pick_phylopic(name = "Bacteria", n = 13,
view = 5, auto = 2),
"Picture"))

# Test attribution information
expect_equal(
length(pick_phylopic(name = "Scleractinia", n = 4, view = 4, auto = 3)),
4)

# Expect warning
expect_warning(pick_phylopic(name = "Acropora cervicornis", n = 10))
Expand Down

0 comments on commit d9707e2

Please sign in to comment.