Request for a modification of function greta_sitrep

Dear all,

I am developing a package that calls greta functions and have met the difficulty that some of the CRAN servers on which these packages are tested have greta installed but incomplete installation regarding python. CRAN experts ask me to exit gracefully in such cases.
I have found the function greta_sitrep very useful to diagnose such cases. Unfortunately, (i) it takes some time (around 10s or more) but I guess it is unavoidable and (ii) its output is in terms of messages which is not easy to handle within my function. More specifically, I have figured out to handle the output within my function with the function capture.output: e.g.: test<-capture.output(greta::greta_sitrep(),type=β€œmessage”), yet I have met the problem that using such a function within a Rmarkdown context makes the function behave badly (much as in: https://github.com/rstudio/rmarkdown/issues/1150).

My question is to know if there is a way to get the output of greta_sitrep directly in a vector and not as messages, much as runjags::testjags does.

I thank you very much in advance.

Sincerely,

FrΓ©dΓ©ric

1 Like

Hi there!

My apologies for the late reply - I’ve been away from the end of April - start of November and am catching up.

You can capture the output of greta_sitrep() using cli::cli_fmt() like so:

cli::cli_fmt(greta::greta_sitrep())
#>  [1] "β„Ή checking if python available"                                          
#>  [2] "βœ” python (v3.8) available"                                               
#>  [3] ""                                                                        
#>  [4] "β„Ή checking if TensorFlow available"                                      
#>  [5] "βœ” TensorFlow (v2.11.0) available"                                        
#>  [6] ""                                                                        
#>  [7] "β„Ή checking if TensorFlow Probability available"                          
#>  [8] "βœ” TensorFlow Probability (v0.19.0) available"                            
#>  [9] ""                                                                        
#> [10] "β„Ή checking if greta conda environment available"                         
#> [11] "βœ” greta conda environment available"                                     
#> [12] ""                                                                        
#> [13] "β„Ή Initialising python and checking dependencies, this may take a moment."
#> [14] "βœ” Initialising python and checking dependencies ... done!"               
#> [15] ""                                                                        
#> [16] "β„Ή greta is ready to use!"

Created on 2024-01-09 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.2 (2023-10-31)
#>  os       macOS Sonoma 14.0
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Australia/Hobart
#>  date     2024-01-09
#>  pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  base64enc     0.1-3      2015-07-28 [1] CRAN (R 4.3.0)
#>  callr         3.7.3      2022-11-02 [1] CRAN (R 4.3.0)
#>  cli           3.6.2      2023-12-11 [1] CRAN (R 4.3.1)
#>  coda          0.19-4     2020-09-30 [1] CRAN (R 4.3.0)
#>  codetools     0.2-19     2023-02-01 [1] CRAN (R 4.3.2)
#>  crayon        1.5.2      2022-09-29 [1] CRAN (R 4.3.0)
#>  digest        0.6.33     2023-07-07 [1] CRAN (R 4.3.0)
#>  evaluate      0.23       2023-11-01 [1] CRAN (R 4.3.1)
#>  fastmap       1.1.1      2023-02-24 [1] CRAN (R 4.3.0)
#>  fs            1.6.3      2023-07-20 [1] CRAN (R 4.3.0)
#>  future        1.33.0     2023-07-01 [1] CRAN (R 4.3.0)
#>  globals       0.16.2     2022-11-21 [1] CRAN (R 4.3.0)
#>  glue          1.6.2      2022-02-24 [1] CRAN (R 4.3.0)
#>  greta         0.4.3.9000 2023-11-17 [1] local
#>  hms           1.1.3      2023-03-21 [1] CRAN (R 4.3.0)
#>  htmltools     0.5.7      2023-11-03 [1] CRAN (R 4.3.1)
#>  jsonlite      1.8.7      2023-06-29 [1] CRAN (R 4.3.0)
#>  knitr         1.45       2023-10-30 [1] CRAN (R 4.3.1)
#>  lattice       0.21-9     2023-10-01 [1] CRAN (R 4.3.2)
#>  lifecycle     1.0.4      2023-11-07 [1] CRAN (R 4.3.1)
#>  listenv       0.9.0      2022-12-16 [1] CRAN (R 4.3.0)
#>  magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.3.0)
#>  Matrix        1.6-1.1    2023-09-18 [1] CRAN (R 4.3.2)
#>  parallelly    1.36.0     2023-05-26 [1] CRAN (R 4.3.0)
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.3.0)
#>  png           0.1-8      2022-11-29 [1] CRAN (R 4.3.0)
#>  prettyunits   1.2.0      2023-09-24 [1] CRAN (R 4.3.1)
#>  processx      3.8.3      2023-12-10 [1] CRAN (R 4.3.1)
#>  progress      1.2.2      2019-05-16 [1] CRAN (R 4.3.0)
#>  ps            1.7.5      2023-04-18 [1] CRAN (R 4.3.0)
#>  purrr         1.0.2      2023-08-10 [1] CRAN (R 4.3.0)
#>  R.cache       0.16.0     2022-07-21 [1] CRAN (R 4.3.0)
#>  R.methodsS3   1.8.2      2022-06-13 [1] CRAN (R 4.3.0)
#>  R.oo          1.25.0     2022-06-12 [1] CRAN (R 4.3.0)
#>  R.utils       2.12.2     2022-11-11 [1] CRAN (R 4.3.0)
#>  R6            2.5.1      2021-08-19 [1] CRAN (R 4.3.0)
#>  Rcpp          1.0.11     2023-07-06 [1] CRAN (R 4.3.0)
#>  reprex        2.0.2      2022-08-17 [1] CRAN (R 4.3.0)
#>  reticulate    1.34.0     2023-10-12 [1] CRAN (R 4.3.1)
#>  rlang         1.1.2      2023-11-04 [1] CRAN (R 4.3.1)
#>  rmarkdown     2.25       2023-09-18 [1] CRAN (R 4.3.1)
#>  rstudioapi    0.15.0     2023-07-07 [1] CRAN (R 4.3.0)
#>  sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.3.0)
#>  styler        1.9.1      2023-03-04 [1] CRAN (R 4.3.0)
#>  tensorflow    2.14.0     2023-09-28 [1] CRAN (R 4.3.1)
#>  tfruns        1.5.1      2022-09-05 [1] CRAN (R 4.3.0)
#>  vctrs         0.6.5      2023-12-01 [1] CRAN (R 4.3.1)
#>  whisker       0.4.1      2022-12-05 [1] CRAN (R 4.3.0)
#>  withr         2.5.2      2023-10-30 [1] CRAN (R 4.3.1)
#>  xfun          0.41       2023-11-01 [1] CRAN (R 4.3.1)
#>  yaml          2.3.8      2023-12-11 [1] CRAN (R 4.3.1)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
#> 
#> ─ Python configuration ───────────────────────────────────────────────────────
#>  python:         /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/bin/python
#>  libpython:      /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/lib/libpython3.8.dylib
#>  pythonhome:     /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2:/Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2
#>  version:        3.8.15 | packaged by conda-forge | (default, Nov 22 2022, 08:49:06)  [Clang 14.0.6 ]
#>  numpy:          /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/lib/python3.8/site-packages/numpy
#>  numpy_version:  1.23.2
#>  tensorflow:     /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/lib/python3.8/site-packages/tensorflow
#>  
#>  NOTE: Python version was forced by use_python() function
#> 
#> ──────────────────────────────────────────────────────────────────────────────

However, in terms of getting things to work in vignettes, etc., on CRAN, we do the following in our vignettes:

```{r setup, include = FALSE}
knitr::opts_chunk$set(comment = NA,
                      eval = greta:::check_tf_version("message"),
                      cache = TRUE)
library (greta)
```

See the vignette source on github for the full context of this.

We could potentially export the check_tf_function in the next greta release if you think this would be useful!

Let me know how you go?

Cheers,

Nick