Skip to content

Commit

Permalink
Fixes for grImport v. 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
willgearty committed Oct 10, 2023
1 parent 1fac8a9 commit 1f1fa70
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Title: Get Silhouettes of Organisms from PhyloPic
Description: Work with the PhyloPic Web Service (<http://api-docs.phylopic.org/v2/>)
to fetch silhouette images of organisms. Includes functions for adding
silhouettes to both base R plots and ggplot2 plots.
Version: 1.2.0.9000
Version: 1.2.0.9001
Authors@R: c(
person(given = "William", family = "Gearty", email = "[email protected]",
role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0076-3262")),
Expand All @@ -29,7 +29,7 @@ Imports:
grid,
graphics,
png,
grImport2,
grImport2 (>= 0.3.0),
rsvg,
httr,
curl,
Expand Down
2 changes: 1 addition & 1 deletion R/geom_phylopic.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ GeomPhylopic <- ggproto("GeomPhylopic", Geom,
"vector image) or class array (for a raster image)."))
}
}
if (params$verbose) {
if (params$verbose&& length(Filter(Negate(is.null), imgs)) > 0) {
get_attribution(img = imgs, text = TRUE)
}
data$name <- NULL
Expand Down
2 changes: 1 addition & 1 deletion R/get_phylopic.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ get_svg <- function(url) {
res <- GET(url = url)
filename <- file.path(tempdir(), "temp.svg")
rsvg_svg(res$content, filename)
readPicture(filename)
readPicture(filename, warn = FALSE)
}

#' @importFrom httr GET
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-add_phylopic_base.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ test_that("add_phylopic_base works", {
# phylopic in background, with name
expect_doppelganger("phylopic in background", function() {
plot(1, 1, type = "n", main = "A cat")
add_phylopic_base(name = "Felis silvestris", verbose = TRUE)
add_phylopic_base(name = "Felis silvestris catus", ysize = .7,
verbose = TRUE)
})

# png phylopic in background
Expand Down
14 changes: 6 additions & 8 deletions tests/testthat/test-geom_phylopic.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ test_that("geom_phylopic works", {
gg <- ggplot(df) +
geom_phylopic(aes(x = x, y = y), img = -5)
expect_error(plot(gg))
suppressWarnings(expect_warning(ggplot_build(
ggplot(df) +
geom_phylopic(aes(x = x, y = y), name = "asdfghjkl")
)))
suppressWarnings(expect_warning(ggplot_build(
ggplot(df) +
geom_phylopic(aes(x = x, y = y), uuid = "asdfghjkl")
)))
gg <- ggplot(df) +
geom_phylopic(aes(x = x, y = y), name = "asdfghjkl", verbose = TRUE)
expect_warning(plot(gg))
gg <- ggplot(df) +
geom_phylopic(aes(x = x, y = y), uuid = "asdfghjkl")
expect_warning(plot(gg))
})

test_that("phylopic_key_glyph works", {
Expand Down
12 changes: 9 additions & 3 deletions tests/testthat/test-phylopic_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ test_that("recolor_phylopic works", {
cat <- get_phylopic("23cd6aa4-9587-4a2e-8e26-de42885004c9")
cat_recolor <- recolor_phylopic(cat, .5, color = "green", fill = "red")
expect_true(is(cat_recolor, "Picture"))
expect_equal(cat_recolor@content[[1]]@content[[1]]@gp$col, "green")
expect_equal(cat_recolor@content[[1]]@content[[1]]@gp$fill, "red")
expect_equal(cat_recolor@content[[1]]@content[[1]]@gp$alpha, .5)
if ("content" %in% slotNames(cat_recolor@content[[1]])) {
expect_equal(cat_recolor@content[[1]]@content[[1]]@gp$col, "green")
expect_equal(cat_recolor@content[[1]]@content[[1]]@gp$fill, "red")
expect_equal(cat_recolor@content[[1]]@content[[1]]@gp$alpha, .5)
} else {
expect_equal(cat_recolor@content[[1]]@gp$col, "green")
expect_equal(cat_recolor@content[[1]]@gp$fill, "red")
expect_equal(cat_recolor@content[[1]]@gp$alpha, .5)
}

cat_png <- get_phylopic("23cd6aa4-9587-4a2e-8e26-de42885004c9",
format = "raster")
Expand Down

0 comments on commit 1f1fa70

Please sign in to comment.