test error
rhijmans opened this issue · comments
I see an error with this test in rasterpic:
expect_error(
rasterpic_img(x, img),
"Cannot reach img on url http://this_is_an_error_url.fake"
)
#Error: `rasterpic_img(x, img)` threw an error with unexpected message.
#Expected match: "Cannot reach img on url http://this_is_an_error_url.fake"
#Actual message: "'img' only accepts 'png', 'jpg' or 'jpeg' files"
Because (in rpic_read
) , this does not throw an error:
img <- "http://this_is_an_error_url.fake"
tmp <- tempfile(fileext = paste0(".", tools::file_ext(img)))
download.file(img, tmp, quiet = TRUE, mode = "wb")
file.info(tmp)
# size isdir mode mtime ctime atime exe
#file60b062b96d1.fake 385 FALSE 666 2023-08-31 17:37:04 2023-08-31 17:36:44 2023-08-31 17:37:04 no
This is on Windows with R 4.3.1
I do get an error with quiet=FALSE
download.file(img, tmp, quiet = F, mode = "wb")
#trying URL 'http://this_is_an_error_url.fake'
#Error in download.file(img, tmp, quiet = F, mode = "wb") :
# cannot open URL 'http://this_is_an_error_url.fake'
#In addition: Warning message:
#In download.file(img, tmp, quiet = F, mode = "wb") :
# URL 'http://this_is_an_error_url.fake/': Timeout of 60 seconds was reached
Hi @rhijmans
Thanks for reporting, however I am not able to reproduce the issue (I tried in Windows and Ubuntu). Just out of curiosity, is this affecting any revdepcheck of terra?
See my reprex results:
Ubuntu
library(rasterpic)
img <- "http://this_is_an_error_url.fake"
x <- sf::st_read(system.file("gpkg/UK.gpkg", package = "rasterpic"),
quiet = TRUE
)
# expect_error(
rasterpic_img(x, img)
#> Error: Cannot reach img on url http://this_is_an_error_url.fake
# "Cannot reach img on url http://this_is_an_error_url.fake"
# )
Created on 2023-09-04 with reprex v2.0.2
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.3.1 (2023-06-16)
#> os Ubuntu 20.04.6 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language (EN)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2023-09-04
#> pandoc 3.1.1 @ /usr/lib/rstudio-server/bin/quarto/bin/tools/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> class 7.3-22 2023-05-03 [2] CRAN (R 4.3.1)
#> classInt 0.4-9 2023-02-28 [1] RSPM (R 4.3.0)
#> cli 3.6.1 2023-03-23 [1] RSPM (R 4.3.0)
#> codetools 0.2-19 2023-02-01 [2] CRAN (R 4.3.1)
#> DBI 1.1.3 2022-06-18 [1] RSPM (R 4.3.0)
#> digest 0.6.33 2023-07-07 [1] RSPM (R 4.3.0)
#> dplyr 1.1.2 2023-04-20 [1] RSPM (R 4.3.0)
#> e1071 1.7-13 2023-02-01 [1] RSPM (R 4.3.0)
#> evaluate 0.21 2023-05-05 [1] RSPM (R 4.3.0)
#> fansi 1.0.4 2023-01-22 [1] RSPM (R 4.3.0)
#> fastmap 1.1.1 2023-02-24 [1] RSPM (R 4.3.0)
#> fs 1.6.3 2023-07-20 [1] RSPM (R 4.3.0)
#> generics 0.1.3 2022-07-05 [1] RSPM (R 4.3.0)
#> glue 1.6.2 2022-02-24 [1] RSPM (R 4.3.0)
#> htmltools 0.5.6 2023-08-10 [1] RSPM (R 4.3.0)
#> KernSmooth 2.23-21 2023-05-03 [2] CRAN (R 4.3.1)
#> knitr 1.43 2023-05-25 [1] RSPM (R 4.3.0)
#> lifecycle 1.0.3 2022-10-07 [1] RSPM (R 4.3.0)
#> magrittr 2.0.3 2022-03-30 [1] RSPM (R 4.3.0)
#> pillar 1.9.0 2023-03-22 [1] RSPM (R 4.3.0)
#> pkgconfig 2.0.3 2019-09-22 [1] RSPM (R 4.3.0)
#> proxy 0.4-27 2022-06-09 [1] RSPM (R 4.3.0)
#> purrr 1.0.2 2023-08-10 [1] RSPM (R 4.3.0)
#> R.cache 0.16.0 2022-07-21 [1] RSPM (R 4.3.0)
#> R.methodsS3 1.8.2 2022-06-13 [1] RSPM (R 4.3.0)
#> R.oo 1.25.0 2022-06-12 [1] RSPM (R 4.3.0)
#> R.utils 2.12.2 2022-11-11 [1] RSPM (R 4.3.0)
#> R6 2.5.1 2021-08-19 [1] RSPM (R 4.3.0)
#> rasterpic * 0.2.2 2023-04-18 [1] RSPM (R 4.3.0)
#> Rcpp 1.0.11 2023-07-06 [1] RSPM (R 4.3.0)
#> reprex 2.0.2 2022-08-17 [1] RSPM (R 4.3.0)
#> rlang 1.1.1 2023-04-28 [1] RSPM (R 4.3.0)
#> rmarkdown 2.24 2023-08-14 [1] RSPM (R 4.3.0)
#> rstudioapi 0.15.0 2023-07-07 [1] RSPM (R 4.3.0)
#> sessioninfo 1.2.2 2021-12-06 [1] RSPM (R 4.3.0)
#> sf 1.0-14 2023-07-11 [1] RSPM (R 4.3.0)
#> styler 1.10.2 2023-08-29 [1] RSPM (R 4.3.0)
#> terra 1.7-39 2023-06-23 [1] RSPM (R 4.3.0)
#> tibble 3.2.1 2023-03-20 [1] RSPM (R 4.3.0)
#> tidyselect 1.2.0 2022-10-10 [1] RSPM (R 4.3.0)
#> units 0.8-3 2023-08-10 [1] RSPM (R 4.3.0)
#> utf8 1.2.3 2023-01-31 [1] RSPM (R 4.3.0)
#> vctrs 0.6.3 2023-06-14 [1] RSPM (R 4.3.0)
#> withr 2.5.0 2022-03-03 [1] RSPM (R 4.3.0)
#> xfun 0.40 2023-08-09 [1] RSPM (R 4.3.0)
#> yaml 2.3.7 2023-01-23 [1] RSPM (R 4.3.0)
#>
#> [1] /cloud/lib/x86_64-pc-linux-gnu-library/4.3
#> [2] /opt/R/4.3.1/lib/R/library
#>
#> ──────────────────────────────────────────────────────────────────────────────
Windows
library(rasterpic)
#> Warning: package 'rasterpic' was built under R version 4.1.3
img <- "http://this_is_an_error_url.fake"
x <- sf::st_read(system.file("gpkg/UK.gpkg", package = "rasterpic"),
quiet = TRUE
)
# expect_error(
rasterpic_img(x, img)
#> Error: Cannot reach img on url http://this_is_an_error_url.fake
# "Cannot reach img on url http://this_is_an_error_url.fake"
# )
Created on 2023-09-04 with reprex v2.0.2
Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#> setting value
#> version R version 4.1.0 (2021-05-18)
#> os Windows 10 x64 (build 19045)
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate Spanish_Spain.1252
#> ctype Spanish_Spain.1252
#> tz Europe/Paris
#> date 2023-09-04
#> pandoc 2.12 @ C:/APS/Anaconda/Scripts/ (via rmarkdown)
#>
#> - Packages -------------------------------------------------------------------
#> ! package * version date (UTC) lib source
#> class 7.3-21 2023-01-23 [1] CRAN (R 4.1.3)
#> classInt 0.4-9 2023-02-28 [1] CRAN (R 4.1.3)
#> cli 3.6.1 2023-03-23 [1] CRAN (R 4.1.3)
#> codetools 0.2-19 2023-02-01 [1] CRAN (R 4.1.3)
#> DBI 1.1.3 2022-06-18 [1] CRAN (R 4.1.3)
#> digest 0.6.31 2022-12-11 [1] CRAN (R 4.1.3)
#> dplyr 1.1.2 2023-04-20 [1] CRAN (R 4.1.3)
#> e1071 1.7-13 2023-02-01 [1] CRAN (R 4.1.3)
#> evaluate 0.21 2023-05-05 [1] CRAN (R 4.1.0)
#> fansi 1.0.4 2023-01-22 [1] CRAN (R 4.1.3)
#> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.1.3)
#> fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.3)
#> generics 0.1.3 2022-07-05 [1] CRAN (R 4.1.3)
#> glue 1.6.2 2022-02-24 [1] CRAN (R 4.1.3)
#> htmltools 0.5.5 2023-03-23 [1] CRAN (R 4.1.3)
#> D KernSmooth 2.23-20 2021-05-03 [2] CRAN (R 4.1.0)
#> knitr 1.43 2023-05-25 [1] CRAN (R 4.1.0)
#> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.1.3)
#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.1.3)
#> pillar 1.9.0 2023-03-22 [1] CRAN (R 4.1.3)
#> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.1.0)
#> proxy 0.4-27 2022-06-09 [1] CRAN (R 4.1.3)
#> purrr 1.0.1 2023-01-10 [1] CRAN (R 4.1.3)
#> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.1.3)
#> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.1.3)
#> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.1.3)
#> R.utils 2.12.2 2022-11-11 [1] CRAN (R 4.1.3)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.3)
#> rasterpic * 0.2.2 2023-04-18 [1] CRAN (R 4.1.3)
#> Rcpp 1.0.10 2023-01-22 [1] CRAN (R 4.1.3)
#> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.1.3)
#> rlang 1.1.0 2023-03-14 [1] CRAN (R 4.1.3)
#> rmarkdown 2.24 2023-08-14 [1] CRAN (R 4.1.0)
#> rstudioapi 0.15.0 2023-07-07 [1] CRAN (R 4.1.0)
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.1.3)
#> sf 1.0-14 2023-07-11 [1] CRAN (R 4.1.0)
#> styler 1.10.2 2023-08-29 [1] CRAN (R 4.1.0)
#> terra 1.7-23 2023-04-08 [1] CRAN (R 4.1.3)
#> tibble 3.2.1 2023-03-20 [1] CRAN (R 4.1.3)
#> tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.1.3)
#> units 0.8-1 2022-12-10 [1] CRAN (R 4.1.3)
#> utf8 1.2.3 2023-01-31 [1] CRAN (R 4.1.3)
#> vctrs 0.6.1 2023-03-22 [1] CRAN (R 4.1.3)
#> withr 2.5.0 2022-03-03 [1] CRAN (R 4.1.3)
#> xfun 0.39 2023-04-20 [1] CRAN (R 4.1.3)
#> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.1.3)
#>
#> [1] C:/<OMITED>/Documents/R/win-library/4.1
#> [2] C:/<OMITED>/R/R-language/library
#>
#> D -- DLL MD5 mismatch, broken installation.
#>
#> ------------------------------------------------------------------------------
Yes, I found this with revdepcheck. But I also see this is a clean R session.
#Type 'q()' to quit R.
img <- "http://this_is_an_error_url.fake"
tmp <- tempfile(fileext = paste0(".", tools::file_ext(img)))
download.file(img, tmp, quiet = TRUE, mode = "wb")
file.exists(tmp)
#[1] TRUE
## but now this also works
download.file(img, tmp, quiet = F, mode = "wb")
#trying URL 'http://this_is_an_error_url.fake'
#Content type 'text/html; charset=utf-8' length 385 bytes
#downloaded 385 bytes
sessionInfo()
#R version 4.3.1 (2023-06-16 ucrt)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#Running under: Windows 10 x64 (build 19043)
#
#Matrix products: default
#
#
#locale:
#[1] LC_COLLATE=English_United States.utf8
#[2] LC_CTYPE=English_United States.utf8
#[3] LC_MONETARY=English_United States.utf8
#[4] LC_NUMERIC=C
#[5] LC_TIME=English_United States.utf8
#
#time zone: America/Los_Angeles
#tzcode source: internal
#
#attached base packages:
#[1] stats graphics grDevices utils datasets methods base
#
#loaded via a namespace (and not attached):
#[1] compiler_4.3.1 tools_4.3.1
I think the inconsistency in behavior is because of what my Internet provider (ATT) does. In most cases, it returns an html page if a URL is not found.
readLines(tmp)
[1] "<html><head><meta http-equiv=\"refresh\" content=\"0;url=http://dnserrorassist.att.net/search/?q=http://this_is_an_error_url.fake%2F%26srchgdeCid%3Daaaaaaaa%26t%3D0%26bc%3D\"/></head><body><script type=\"text/javascript\">window.location=\"http://dnserrorassist.att.net/search/?q=\"+escape(window.location)+\"&r=\"+escape(document.referrer)+\"&t=0&srchgdeCid=aaaaaaaa&bc=\";</script></body></html>"
So this probably works fine on CRAN. But to make this work more smoothly (at least for me), perhaps you can check that you get an error, without specifying the error message. Right now you are essentially checking what download.file
does, and this is perhaps not the best place for that.
@rhijmans now the test just expects an error, not requiring an explicit message. I’ll try to send a new version to CRAN during this week.
Thanks, there is no hurry, as it probably works fine as-is on the CRAN computers.