Deleting brms messages from RMarkdown document

29 views Asked by At

When I run the following code in my console, all is well:

dat <- data.frame(
  Status  =  c("Primary", "Primary", "Secondary","Secondary"), 
  RX = c("B","P","B","P"),
  Deaths  =  c(75, 109, 359, 311), #JAMA (primary) = 75 NEJM (total) = 434 (bempedoic) - total mortality
  N = c(2100,2106,4892,4872)
) 

mod <- brms::brm(Deaths | trials(N) ~ RX * Status, data = dat, family = binomial(link="logit"), refresh=0)

mod
sessionInfo()

R> mod
 Family: binomial 
  Links: mu = logit 
Formula: Deaths | trials(N) ~ RX * Status 
   Data: dat (Number of observations: 4) 
  Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
         total post-warmup draws = 4000

Population-Level Effects: 
                    Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept              -3.30      0.12    -3.53    -3.07 1.00     1415     2076
RXP                     0.38      0.16     0.09     0.70 1.00     1361     1676
StatusSecondary         0.76      0.13     0.51     1.03 1.00     1427     1665
RXP:StatusSecondary    -0.53      0.18    -0.89    -0.19 1.00     1343     1592

Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).

R> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.0

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-x86_64/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: America/Toronto
tzcode source: internal

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

loaded via a namespace (and not attached):
  [1] tidyselect_1.2.0     dplyr_1.1.3          farver_2.1.1         loo_2.6.0            fastmap_1.1.1        TH.data_1.1-2       
  [7] tensorA_0.36.2       shinystan_2.6.0      promises_1.2.0.1     shinyjs_2.1.0        digest_0.6.33        estimability_1.4.1  
 [13] mime_0.12            lifecycle_1.0.3      StanHeaders_2.26.27  ellipsis_0.3.2       survival_3.5-7       processx_3.8.2      
 [19] magrittr_2.0.3       posterior_1.4.1      compiler_4.3.1       rlang_1.1.2          tools_4.3.1          igraph_1.5.1        
 [25] utf8_1.2.4           yaml_2.3.7           knitr_1.43           prettyunits_1.2.0    bridgesampling_1.1-2 htmlwidgets_1.6.2   
 [31] pkgbuild_1.4.2       plyr_1.8.8           dygraphs_1.1.1.6     multcomp_1.4-25      abind_1.4-5          miniUI_0.1.1.1      
 [37] grid_4.3.1           stats4_4.3.1         fansi_1.0.5          xts_0.13.1           xtable_1.8-4         colorspace_2.1-0    
 [43] inline_0.3.19        ggplot2_3.4.4        MASS_7.3-60          emmeans_1.8.7        scales_1.2.1         gtools_3.9.4        
 [49] cli_3.6.1            mvtnorm_1.2-3        rmarkdown_2.24       crayon_1.5.2         generics_0.1.3       RcppParallel_5.1.7  
 [55] rstudioapi_0.15.0    reshape2_1.4.4       rstan_2.26.23        stringr_1.5.0        splines_4.3.1        shinythemes_1.2.0   
 [61] bayesplot_1.10.0     parallel_4.3.1       matrixStats_1.0.0    base64enc_0.1-3      brms_2.19.0          vctrs_0.6.4         
 [67] sandwich_3.0-2       Matrix_1.5-4.1       jsonlite_1.8.7       callr_3.7.3          crosstalk_1.2.0      glue_1.6.2          
 [73] codetools_0.2-19     ps_1.7.5             DT_0.28              distributional_0.3.2 stringi_1.7.12       gtable_0.3.4        
 [79] QuickJSR_1.0.6       later_1.3.1          munsell_0.5.0        tibble_3.2.1         colourpicker_1.2.0   pillar_1.9.0        
 [85] htmltools_0.5.6      Brobdingnag_1.2-9    R6_2.5.1             evaluate_0.22        shiny_1.7.4          lattice_0.21-8      
 [91] markdown_1.7         backports_1.4.1      threejs_0.3.3        httpuv_1.6.11        rstantools_2.3.1     Rcpp_1.0.11         
 [97] coda_0.19-4          gridExtra_2.3        nlme_3.1-162         checkmate_2.2.0      xfun_0.40            zoo_1.8-12          
[103] pkgconfig_2.0.3

However when I run the same code in RMarkdown I get the same output as from the console but also the following gibberish (at least to me).

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.0.40.1)’
## using SDK: ‘’
## clang -arch x86_64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DUSE_STANC3 -DSTRICT_R_HEADERS  -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/opt/R/x86_64/include    -fPIC  -falign-functions=64 -Wall -g -O2  -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
##                ^
##                ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
##          ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1

it doesn’t cause the RMarkdown file to crash and gives the same answer but obviously doesn't help the overall aesthetics! I have tried all suppress_message commands that i can find but no luck. Also no help from Stan forum. Any suggestions? Thanks

1

There are 1 answers

0
Jamie On

I was able to prevent this exact kind of error message from appearing in quarto/markdown by adding results = "hide" to the top of the section, for example:

```{r, warning = FALSE, message = FALSE, results = "hide", fig.height = 9}```