File: summary_stats_latex.R

package info (click to toggle)
r-cran-shinystan 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,172 kB
  • sloc: sh: 15; makefile: 7
file content (38 lines) | stat: -rw-r--r-- 1,087 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
summary_stats_latex <- reactive({
  params <- unique(.update_params_with_groups(input$tex_params, PARAM_NAMES))
  nParams <- length(params)
  if (nParams == 0)
    params <- PARAM_NAMES
  if (nParams == 1) {
    x <- do.call(".param_summary", args = list(
      param = params, 
      summary = SUMMARY
    ))
  } else {
    x <- do.call(".tex_summary", args = list(
      summary = SUMMARY[params,], 
      cols = input$tex_columns
    ))
  }
  
  pkgs <- input$tex_pkgs
  tab_env <- if ("Longtable" %in% pkgs)
    "longtable" else getOption("xtable.tabular.environment", "tabular")
  caption <- if (nzchar(input$tex_caption)) 
    input$tex_caption else NULL
  xt <- xtable::xtable(x, caption = caption)
  xtable::digits(xt) <- input$tex_digits
  if ("n_eff" %in% colnames(xt))
    xtable::display(xt)[1 + which(colnames(xt) == "n_eff")] <- "d"
  xtable::print.xtable(
    xt,
    booktabs = "Booktabs" %in% pkgs,
    tabular.environment = tab_env,
    include.rownames = FALSE
  )
})

output$summary_stats_latex_out <- renderPrint({
  input$tex_go
  isolate(summary_stats_latex())
})