wch / webshot

Take screenshots of web pages from R
http://wch.github.io/webshot/
227 stars 40 forks source link

`if` statement with length > 1 vector #101

Closed shirdekel closed 1 year ago

shirdekel commented 3 years ago

Using a vector input for the expand argument gives an error when setting the _R_CHECK_LENGTH_1_CONDITION_ as per https://github.com/HenrikBengtsson/Wishlist-for-R/issues/48. The issue seems to be in the argToVec() internal function and would also apply to a vector of cliprect or selector.

webshot::webshot("https://www.r-project.org/", "r-expand.png",
    selector = "#getting-started",
    expand = c(40, 20, 40, 20)
)

Sys.setenv("_R_CHECK_LENGTH_1_LOGIC2_" = "verbose")
Sys.setenv("_R_CHECK_LENGTH_1_CONDITION_" = "true")

webshot::webshot("https://www.r-project.org/", "r-expand.png",
    selector = "#getting-started",
    expand = c(40, 20, 40, 20)
)
#> Error in is.null(x) || is.na(x): 'length(x) = 4 > 1' in coercion to 'logical(1)'

Created on 2021-05-20 by the reprex package (v1.0.0)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.2 (2020-06-22) #> os macOS Mojave 10.14.6 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_AU.UTF-8 #> ctype en_AU.UTF-8 #> tz Australia/Sydney #> date 2021-05-20 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> backports 1.2.1 2020-12-09 [1] CRAN (R 4.0.2) #> callr 3.7.0 2021-04-20 [1] CRAN (R 4.0.2) #> cli 2.5.0 2021-04-26 [1] CRAN (R 4.0.2) #> crayon 1.4.1 2021-02-08 [1] CRAN (R 4.0.2) #> curl 4.3.1 2021-04-30 [1] CRAN (R 4.0.2) #> data.table 1.14.0 2021-02-21 [1] CRAN (R 4.0.2) #> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.2) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.0.2) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0) #> fansi 0.4.2 2021-01-15 [1] CRAN (R 4.0.2) #> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.2) #> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2) #> highr 0.9 2021-04-16 [1] CRAN (R 4.0.2) #> htmltools 0.5.1.1 2021-01-22 [1] CRAN (R 4.0.2) #> httr 1.4.2 2020-07-20 [1] CRAN (R 4.0.2) #> jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.0.2) #> knitr 1.33 2021-04-24 [1] CRAN (R 4.0.2) #> lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.0.2) #> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.2) #> mime 0.10 2021-02-13 [1] CRAN (R 4.0.2) #> pillar 1.6.1 2021-05-16 [1] CRAN (R 4.0.2) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0) #> processx 3.5.2 2021-04-30 [1] CRAN (R 4.0.2) #> ps 1.6.0 2021-02-28 [1] CRAN (R 4.0.2) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.0) #> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.2) #> reprex 1.0.0 2021-01-27 [1] CRAN (R 4.0.2) #> rlang 0.4.11 2021-04-30 [1] CRAN (R 4.0.2) #> rmarkdown 2.8.1 2021-05-13 [1] Github (rstudio/rmarkdown@9e19405) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.0) #> stringi 1.6.1 2021-05-10 [1] CRAN (R 4.0.2) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.0) #> styler 1.3.2 2020-02-23 [1] CRAN (R 4.0.0) #> tibble 3.1.2 2021-05-16 [1] CRAN (R 4.0.2) #> utf8 1.2.1 2021-03-12 [1] CRAN (R 4.0.2) #> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.0.2) #> webshot 0.5.2 2019-11-22 [1] CRAN (R 4.0.0) #> withr 2.4.2 2021-04-18 [1] CRAN (R 4.0.2) #> xfun 0.22 2021-03-11 [1] CRAN (R 4.0.2) #> xml2 1.3.2 2020-04-23 [1] CRAN (R 4.0.0) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.2) #> #> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library ```
beanumber commented 2 years ago

Due to the changes in the behavior of || this is now throwing a WARNING in R 4.2.0 when I use it at the console, but more problematically, it's throwing an ERROR when I try to wrap webshot() in my package code.

Could this be fixed by throwing some any() or all()s into the argToVec() function??

spsanderson commented 1 year ago

I just upgraded to 4.3 yesterday and I am having the same issue.