insightsengineering / teal.widgets

shiny widgets for teal applications
https://insightsengineering.github.io/teal.widgets/
Other
4 stars 6 forks source link

Executing tests freezes R process #216

Open pawelru opened 9 months ago

pawelru commented 9 months ago
r$> devtools::test()
ℹ Testing teal.widgets
Loading required package: withr
✔ | F W  S  OK | Context
✔ |         33 | ggplot2_args                                                
(...)
⠏ |          0 | plot_with_settings                                     

The issue is here. Below line freezes R

is_draw(\() print_plot(\() ggplot2::ggplot(mtcars), \() "ANYTHING"))

This does work in CI (and CRAN checks) but it does not work locally which is very frustrating. It might be due to the fact that I am using VSCode which has its own engine for graphics

r$> sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

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

time zone: Europe/Zurich
tzcode source: internal

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

other attached packages:
[1] teal.widgets_0.4.2.9000 testthat_3.2.1         

loaded via a namespace (and not attached):
 [1] gtable_0.3.4       bslib_0.6.1        ggplot2_3.4.4     
 [4] shinyjs_2.1.0      htmlwidgets_1.6.4  formatters_0.5.5  
 [7] devtools_2.4.5     remotes_2.4.2.1    vctrs_0.6.5       
[10] tools_4.3.2        generics_0.1.3     tibble_3.2.1      
[13] fansi_1.0.6        pkgconfig_2.0.3    R.oo_1.25.0       
[16] checkmate_2.3.1    desc_1.4.3         lifecycle_1.0.4   
[19] R.cache_0.16.0     compiler_4.3.2     stringr_1.5.1     
[22] brio_1.1.4         munsell_0.5.0      httpuv_1.6.13     
[25] shinyWidgets_0.8.1 htmltools_0.5.7    usethis_2.2.2     
[28] sass_0.4.8         later_1.3.2        pillar_1.9.0      
[31] jquerylib_0.1.4    urlchecker_1.0.1   ellipsis_0.3.2    
[34] R.utils_2.12.3     cachem_1.0.8       rtables_0.6.6     
[37] sessioninfo_1.2.2  mime_0.12          styler_1.10.2     
[40] tidyselect_1.2.0   digest_0.6.34      stringi_1.8.3     
[43] dplyr_1.1.4        purrr_1.0.2        rprojroot_2.0.4   
[46] fastmap_1.1.1      grid_4.3.2         colorspace_2.1-0  
[49] cli_3.6.2          magrittr_2.0.3     pkgbuild_1.4.3    
[52] utf8_1.2.4         withr_3.0.0        scales_1.3.0      
[55] promises_1.2.1     backports_1.4.1    R.methodsS3_1.8.2 
[58] memoise_2.0.1      shiny_1.8.0        miniUI_0.1.1.1    
[61] profvis_0.3.8      rlang_1.1.3        Rcpp_1.0.12       
[64] xtable_1.8-4       glue_1.7.0         pkgload_1.3.4     
[67] rstudioapi_0.15.0  jsonlite_1.8.8     R6_2.5.1          
[70] fs_1.6.3
chlebowa commented 9 months ago

It might ba an app with if (interactive()). You are running the tests interactively.

pawelru commented 9 months ago

That was also my guess but no. These are the erroneous lines and no shiny in there: https://github.com/insightsengineering/teal.widgets/blob/e59ba815781604af411ac6c88ed96d5acbfa49a2/tests/testthat/test-plot_with_settings.R#L62-L94

pawelru commented 9 months ago

Using debugger I managed to find that it's grDevices::dev.off() executed on exit from is_draw():

https://github.com/insightsengineering/teal.widgets/blob/e59ba815781604af411ac6c88ed96d5acbfa49a2/tests/testthat/helpers-with-settings.R#L82-L97

After temp removing this line, the second call to grDevices::graphics.off() also freezes the session

pawelru commented 9 months ago

Found a workaround but this is still an issue. In VSCode, turn off r.plot.useHttpgd setting

averissimo commented 9 months ago

It doesn't freeze on rstudio nor on the console

averissimo commented 9 months ago

Is the r.plot.useHttpgd defined via R's options() or via vscode's GUI?

We could force change that option for a set of affected tests or globally if it makes sense

kartikeyakirar commented 9 months ago

for me also it does not freeze on Rstudio

image
chlebowa commented 9 months ago

It doesn't freeze on rstudio nor on the console

Sounds like an IDE issue.