HTML output of stargazer() is not rendering to HTML directly, but instead shows the HTML code

Hi, I'm trying to render a table with the R package stargazer() to HTML with pandoc 2.11.0.4. I'm using the YAML header bookdown::html_document2: for the output. However this is also the same if I just use output: html_document in the YAML.

The following code (from a mixed model using lme4()):

stargazer(mixed.lean, digit.separator = "", digits = 3, type = "html", title = "", style = "default")

Looks like that in the rendered HTML file

What can I do to make the HTML code be directly rendered in the HTML?

R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Manjaro Linux

Matrix products: default
BLAS:   /usr/lib/libblas.so.3.9.0
LAPACK: /usr/lib/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C               LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8    
 [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8    LC_PAPER=en_AU.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] stargazer_5.2.2  lme4_1.1-25      Matrix_1.2-18    Hmisc_4.4-2      Formula_1.2-4    survival_3.2-7   lattice_0.20-41 
 [8] gvlma_1.0.0.3    car_3.0-10       carData_3.0-4    jtools_2.1.1     rstatix_0.6.0    kableExtra_1.3.1 forcats_0.5.0   
[15] stringr_1.4.0    dplyr_1.0.2      purrr_0.3.4      readr_1.4.0      tidyr_1.1.2      tibble_3.0.4     tidyverse_1.3.0 
[22] sjPlot_2.8.6     ggplot2_3.3.2    devtools_2.3.2   usethis_1.6.3   

loaded via a namespace (and not attached):
  [1] readxl_1.3.1        backports_1.2.0     splines_4.0.3       TH.data_1.0-10      digest_0.6.27       htmltools_0.5.0    
  [7] rsconnect_0.8.16    fansi_0.4.1         magrittr_2.0.1      checkmate_2.0.0     memoise_1.1.0       cluster_2.1.0      
 [13] openxlsx_4.2.3      remotes_2.2.0       modelr_0.1.8        sandwich_3.0-0      prettyunits_1.1.1   jpeg_0.1-8.1       
 [19] colorspace_2.0-0    rvest_0.3.6         haven_2.3.1         xfun_0.19           callr_3.5.1         crayon_1.3.4       
 [25] jsonlite_1.7.1      zoo_1.8-8           glue_1.4.2          gtable_0.3.0        emmeans_1.5.2-1     webshot_0.5.2      
 [31] sjstats_0.18.0      sjmisc_2.8.5        pkgbuild_1.1.0      abind_1.4-5         scales_1.1.1        mvtnorm_1.1-1      
 [37] DBI_1.1.0           ggeffects_1.0.0     Rcpp_1.0.5          viridisLite_0.3.0   xtable_1.8-4        performance_0.5.1  
 [43] htmlTable_2.1.0     foreign_0.8-80      htmlwidgets_1.5.2   httr_1.4.2          RColorBrewer_1.1-2  ellipsis_0.3.1     
 [49] pkgconfig_2.0.3     farver_2.0.3        nnet_7.3-14         dbplyr_2.0.0        tidyselect_1.1.0    labeling_0.4.2     
 [55] rlang_0.4.9         effectsize_0.4.0    munsell_0.5.0       cellranger_1.1.0    tools_4.0.3         cli_2.2.0          
 [61] generics_0.1.0      sjlabelled_1.1.7    broom_0.7.2         evaluate_0.14       yaml_2.2.1          processx_3.4.5     
 [67] knitr_1.30          fs_1.5.0            zip_2.1.1           pander_0.6.3        nlme_3.1-149        xml2_1.3.2         
 [73] compiler_4.0.3      rstudioapi_0.13     curl_4.3            png_0.1-7           testthat_3.0.0      reprex_0.3.0       
 [79] statmod_1.4.35      stringi_1.5.3       highr_0.8           ps_1.4.0            parameters_0.9.0    desc_1.2.0         
 [85] nloptr_1.2.2.2      vctrs_0.3.5         pillar_1.4.7        lifecycle_0.2.0     estimability_1.3    data.table_1.13.2  
 [91] insight_0.11.0      R6_2.5.0            latticeExtra_0.6-29 bookdown_0.21       gridExtra_2.3       rio_0.5.16         
 [97] sessioninfo_1.1.1   codetools_0.2-16    boot_1.3-25         MASS_7.3-53         assertthat_0.2.1    pkgload_1.1.0      
[103] rprojroot_2.0.2     withr_2.3.0         multcomp_1.4-15     bayestestR_0.7.5    hms_0.5.3           grid_4.0.3         
[109] rpart_4.1-15        coda_0.19-4         minqa_1.2.4         rmarkdown_2.5       lubridate_1.7.9.2   base64enc_0.1-3   
1 Like

What are your chunk options. Try using the results = 'asis' option in the chunk. you might also need to cat(stargazer(...))

I'm not a stargazer user, so I'm mostly guessing from experience with other outputs.

4 Likes

This did the trick, thank you!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.