Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error handling when specified raster size doesn't exist #46

Closed
bschilder opened this issue Apr 1, 2023 · 6 comments · Fixed by #47
Closed

Better error handling when specified raster size doesn't exist #46

bschilder opened this issue Apr 1, 2023 · 6 comments · Fixed by #47
Assignees
Labels

Comments

@bschilder
Copy link
Contributor

Describe the bug
get_phylopic gives an error about the URL length for certain species.

To Reproduce

s <- "mus musculus"
URL <- rphylopic::get_uuid(name = s,
                                       url = TRUE)  
png_data <- rphylopic::get_phylopic(uuid = names(URL),
                                                    format = "512")
Error in parse_url(url) : length(url) == 1 is not TRUE
12.
stop(simpleError(msg, call = if (p <- sys.parent(1L)) sys.call(p)))
11.
stopifnot(length(url) == 1)
10.
parse_url(url)
9.
is.url(url)
8.
stopifnot(is.url(url))
7.
build_url(parse_url(url)[c("scheme", "hostname", "port")])
6.
handle_name(url)
5.
handle_find(url)
4.
handle_url(handle, url, ...)
3.
GET(url = x)
2.
get_png(url)
1.
rphylopic::get_phylopic(uuid = names(URL), format = "512")

Expected behavior

If more than 1 URL is available, the function will automatically pick the first one.

If none are available, an error message will tell the user this.

Desktop (please complete the following information):

  • OS: macOS Ventura 13.2.1
  • rphylopic version: 1.0.0
  • R Version: 4.2.1 (2022-06-23)

Session info

``` R version 4.2.1 (2022-06-23) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Ventura 13.2.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] shiny_1.7.4 orthogene_1.5.1 rphylopic_1.0.0 ggplot2_3.4.1 ggtree_3.6.2

loaded via a namespace (and not attached):
[1] utf8_1.2.3 gptstudio_0.1.0 devoptera_0.99.0 R.utils_2.12.2
[5] RUnit_0.4.32 tidyselect_1.2.0 RSQLite_2.3.0 AnnotationDbi_1.60.2
[9] htmlwidgets_1.6.2 grid_4.2.1 combinat_0.0-8 chatgpt_0.2.2
[13] devtools_2.4.5 munsell_0.5.0 codetools_0.2-19 ragg_1.2.5
[17] miniUI_0.1.1.1 withr_2.5.0 colorspace_2.1-0 Biobase_2.58.0
[21] TreeTools_1.9.1 knitr_1.42 rstudioapi_0.14 stats4_4.2.1
[25] ggsignif_0.6.4 MatrixGenerics_1.10.0 Rdpack_2.4 labeling_0.4.2
[29] GenomeInfoDbData_1.2.9 mnormt_2.1.1 optimParallel_1.0-2 topGO_2.50.0
[33] bit64_4.0.5 farver_2.1.1 rprojroot_2.0.3 coda_0.19-4
[37] vctrs_0.6.1 treeio_1.23.1 generics_0.1.3 clusterGeneration_1.3.7
[41] xfun_0.37 R6_2.5.1 doParallel_1.0.17 GenomeInfoDb_1.34.9
[45] rsvg_2.4.0 grImport2_0.2-0 bitops_1.0-7 cachem_1.0.7
[49] gridGraphics_0.5-1 DelayedArray_0.24.0 assertthat_0.2.1 promises_1.2.0.1
[53] scales_1.2.1 gtable_0.3.3 biocViews_1.66.3 processx_3.8.0
[57] phangorn_2.11.1 rlang_1.1.0 systemfonts_1.0.4 scatterplot3d_0.3-43
[61] rstatix_0.7.2 lazyeval_0.2.2 broom_1.0.4 BiocManager_1.30.20
[65] yaml_2.3.7 abind_1.4-5 ggimage_0.3.1.002 backports_1.4.1
[69] httpuv_1.6.9 RBGL_1.74.0 tools_4.2.1 usethis_2.1.6
[73] ggplotify_0.1.0 ellipsis_0.3.2 jquerylib_0.1.4 RColorBrewer_1.1-3
[77] BiocGenerics_0.44.0 sessioninfo_1.2.2 Rcpp_1.0.10 plyr_1.8.8
[81] base64enc_0.1-3 zlibbioc_1.44.0 purrr_1.0.1 RCurl_1.98-1.10
[85] ps_1.7.3 prettyunits_1.1.1 ggpubr_0.6.0 urlchecker_1.0.1
[89] fontawesome_0.5.0 S4Vectors_0.36.2 grr_0.9.5 fs_1.6.1
[93] here_1.0.1 magrittr_2.0.3 data.table_1.14.8 magick_2.7.4
[97] SparseM_1.81 R.cache_0.16.0 matrixStats_0.63.0 pkgload_1.3.2
[101] patchwork_1.1.2 mime_0.12 evaluate_0.20 xtable_1.8-4
[105] XML_3.99-0.14 jpeg_0.1-10 IRanges_2.32.0 compiler_4.2.1
[109] tibble_3.2.1 maps_3.4.1 crayon_1.5.2 R.oo_1.25.0
[113] htmltools_0.5.4 ggfun_0.0.9 later_1.3.0 tidyr_1.3.0
[117] aplot_0.1.10 expm_0.999-7 DBI_1.1.3 gprofiler2_0.2.1
[121] MASS_7.3-58.3 babelgene_22.9 Matrix_1.5-3 car_3.1-1
[125] piggyback_0.1.4 cli_3.6.1 quadprog_1.5-8 R.methodsS3_1.8.2
[129] rbibutils_2.2.13 parallel_4.2.1 igraph_1.4.1 GenomicRanges_1.50.2
[133] pkgconfig_2.0.3 numDeriv_2016.8-1.1 plotly_4.10.1 foreach_1.5.2
[137] bslib_0.4.2 stringdist_0.9.10 XVector_0.38.0 BiocCheck_1.34.3
[141] yulab.utils_0.0.6 stringr_1.5.0 callr_3.7.3 digest_0.6.31
[145] phytools_1.5-1 graph_1.76.0 Biostrings_2.66.0 rmarkdown_2.20.1
[149] fastmatch_1.1-3 tidytree_0.4.2 curl_5.0.0 lifecycle_1.0.3
[153] nlme_3.1-162 jsonlite_1.8.4 carData_3.0-5 OmaDB_2.14.0
[157] desc_1.4.2 viridisLite_0.4.1 fansi_1.0.4 pillar_1.9.0
[161] lattice_0.20-45 homologene_1.4.68.19.3.27 KEGGREST_1.38.0 fastmap_1.1.1
[165] httr_1.4.5 plotrix_3.8-2 pkgbuild_1.4.0 GO.db_3.16.0
[169] glue_1.6.2 remotes_2.4.2 png_0.1-8 iterators_1.0.14
[173] bit_4.0.5 sass_0.4.5 stringi_1.7.12 profvis_0.3.7
[177] blob_1.2.4 textshaping_0.3.6 memoise_2.0.1 dplyr_1.1.1
[181] ape_5.7-1

</details>
@willgearty
Copy link
Collaborator

It looks like the error here is due to there not being a 512pixel png available for that image: https://www.phylopic.org/images/c8f71c27-71db-4b34-ac2d-e97fea8762cf/mus-musculus.

@willgearty
Copy link
Collaborator

We should have better error handling in cases like these.

@willgearty willgearty changed the title get_phylopic: Error in parse_url(url) : length(url) == 1 is not TRUE Better error handling when specified raster size doesn't exist Apr 1, 2023
@LewisAJones
Copy link
Collaborator

Thanks for the catch @bschilder! As @willgearty has said, this is more to do with what is available on PhyloPic rather than the package itself. As a user, what would be your preferred handling in the event of these circumstances? An error being thrown or a warning and an svg (or other format) being returned by default? I can see value in both.

Thanks for being an active user!

@bschilder
Copy link
Contributor Author

Thanks for being so responsive @willgearty @LewisAJones ! This makes sense to me.

Thanks for the catch @bschilder! As @willgearty has said, this is more to do with what is available on PhyloPic rather than the package itself. As a user, what would be your preferred handling in the event of these circumstances? An error being thrown or a warning and an svg (or other format) being returned by default? I can see value in both.

I can also see value in both approaches here. But in my particular case, I'd lean towards providing a warning message and returning NULL because I'm trying to gather images for many species within a parallelised loop.
https://github.com/neurogenomics/orthogene/blob/fa04f484de87f42dea5f9e69b1ee149b6f025c4f/R/get_silhouettes.R#L68

The warning + return NULL behavior would save me having to add a tryCatch (which is a rather sledgehammer-ish approach that I try to avoid bc it potentially obscures errors occurring for other reasons).

On that note, vectorizing the get_uuid and get_phylopic functions so that they can take multiple species at once and return the outputs as a list or data.frame would be a nice feature. But I'll leave it to you guys whether that's something you'd like to add.

@bschilder
Copy link
Contributor Author

I should mention, I'd also be happy to make a PR with a version of my get_silhouettes function so it could be integrated directly into rphylopic, if you think that would be a useful feature.
https://github.com/neurogenomics/orthogene/blob/main/R/get_silhouettes.R

@keesey
Copy link

keesey commented Apr 5, 2023

Given that images submitted in raster formats don't have a predictable set of sizes, I wonder if it would be better to pass minimum/maximum width/height/dimension? (Where dimension = max(width, height).)

(At some point I will be going back and vectorizing more silhouettes, but not for a while.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants