library(dplyr)
library(purrr)

\clearpage

Data

Mostly working with this data; but some others come in later to illustrate certain features.

library(pmtables)
library(yspec)
spec <- ys_help$spec()

data <- pmt_summarized

data

wrap

There is a wrap function in this document. Don't worry about that; it just puts the output into a table environment and sends the output to get rendered in markdown.

\clearpage

Simple table

data %>% stable(units = ys_get_unit(spec, parens = TRUE)) %>% st_asis()

\clearpage

Long table

data <- ptdata()
data <- map_dfr(1:3, ~ data) %>% arrange(STUDY,DOSE,FORM)
data %>%
  stable_long(
    panel = "STUDY", cols_bold = TRUE,
    units = ys_get_unit(spec, parens = TRUE),
    notes = "The results look great!",
    clear_reps = "DOSE",
    cols_rename = c(Formulation  = "FORM"),
    r_file = "foo.R", output_file = "../deliv/table/output.tex",
    note_config = noteconf(type = "minipage", width = 0.8,table_skip = 0.1)
  ) %>% st_asis()

\clearpage

With span

data %>%
  stable_long(
    panel = "STUDY", cols_bold = TRUE,
    notes = "The results look great!",
    clear_reps = "DOSE",
    span = colgroup("A Group of Columns", N:SCR),
    cols_rename = c(Formulation  = "FORM"),
    r_file = "foo.R", output_file = "../deliv/table/output.tex",
    note_config = noteconf(type = "minipage", width = 0.8,table_skip = 0.1)
  ) %>% st_asis()

\clearpage

With both

data %>%
  stable_long(
    panel = "STUDY", cols_bold = TRUE,
    units = ys_get_unit(spec, parens = TRUE),
    span = colgroup("A Group of Columns", N:SCR),
    notes = "The results look great!",
    clear_reps = "DOSE",
    cols_rename = c(Formulation  = "FORM"),
    r_file = "foo.R", output_file = "../deliv/table/output.tex",
    note_config = noteconf(type = "minipage", width = 0.8,table_skip = 0.1)
  ) %>% st_asis()

\clearpage

Pass in the caption

data %>%
  stable_long(
    panel = "STUDY", 
    cols_bold = TRUE,
    notes = "The results look great!",
    clear_reps = "DOSE",
    lt_cap_text  = "This is a super-interesting table.", 
    note_config = noteconf(type = "minipage", table_skip = 0.1)
  ) %>% st_asis()

\clearpage

Use a caption from tex macro

- Then create the table with:

```{=latex}
\newcommand{\myfbtable}{This is a caption from a macro}\vskip 0.5cm
data %>%
  stable_long(
    panel = "STUDY", 
    cols_bold = TRUE,
    notes = "FORM: formulation",
    r_file = "demo-longtable.Rmd", 
    output_file = "foo.tex",
    clear_reps = "DOSE",
    lt_cap_macro  = "myfbtable", 
    note_config = noteconf(width = 0.7, type = "minipage", table_skip = 0.1)
  ) %>% st_asis()

\clearpage

Pass in the caption with short

data %>%
  stable_long(
    panel = "STUDY", 
    cols_bold = TRUE,
    notes = "The results look great!",
    clear_reps = "DOSE",
    lt_cap_short = "a table",
    lt_cap_text  = "This is a super-interesting table.", 
    note_config = noteconf(type = "minipage", table_skip = 0.1)
  ) %>% st_asis()

\clearpage

Reduce row space

data %>%
  stable_long(
    panel = "STUDY", 
    cols_bold = TRUE,
    notes = "FORM: formulation",
    r_file = "demo-longtable.Rmd", 
    output_file = "foo.tex",
    clear_reps = "DOSE",
    sizes = tab_size(row = 1),
    note_config = noteconf(width = 0.7, type = "minipage", table_skip = 0.1)
  ) %>% st_asis()

\clearpage

Extra spance

data %>%
  stable_long(
    panel = "STUDY", 
    cols_bold = TRUE,
    notes = "FORM: formulation",
    r_file = "demo-longtable.Rmd", 
    output_file = "foo.tex",
    clear_reps = "DOSE",
    sizes = tab_size(lt_row = 2),
    note_config = noteconf(width = 0.7, type = "minipage", table_skip = 0.1)
  ) %>% st_asis()

\clearpage

data %>%
  stable_long(
    panel = "STUDY", 
    cols_bold = TRUE,
    notes = "FORM: formulation",
    r_file = "demo-longtable.Rmd", 
    output_file = "foo.tex",
    clear_reps = "DOSE",
    note_config = noteconf(width = 0.7, type = "minipage", table_skip = 0.1)
  ) %>% st_asis()

\clearpage

Increase col space

data %>%
  stable_long(
    panel = "STUDY", 
    cols_bold = TRUE,
    notes = "FORM: formulation",
    r_file = "demo-longtable.Rmd", 
    output_file = "foo.tex",
    clear_reps = "DOSE",
    sizes = tab_size(row = 1, col = 1),
    note_config = noteconf(width = 0.7, type = "minipage", table_skip = 0.1)
  ) %>% st_asis()

\clearpage

Change the font size

stable_long(stdata(), sizes = tab_size(font = "scriptsize")) %>% 
  st_asis()

\clearpage

Annotate

stable_long(
  data[1:10,],
  r_file = "foo.R",
  output_file = "foo.tex",
  notes = c("Data were analyzed in quadruplicate.", "The results are very clear."),
) %>% st_asis()


metrumresearchgroup/pmtables documentation built on Oct. 27, 2024, 5:16 p.m.