library(dplyr) library(purrr)
\clearpage
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 head(data)
In this document, we are rendering tables inline as we knit. To accomplish this
we need to pipe tables to st_asis()
and you will see that in every example.
If you are knitting a document and want to include a table, you should do this.
If you are not knitting a document with included tables, you shouldn't use
st_asis()
\clearpage
threeparttable
data %>% stable(cols_bold=TRUE) %>% st_asis()
\clearpage
stable( data, r_file = "foo.R", output_file = "foo.tex", notes = c("Data were analyzed in quadruplicate.", "The results are very clear."), ) %>% st_asis()
\clearpage
stable( data, note_config = noteconf(type = "minipage", width = 0.85), notes = c("Data were analyzed in quadruplicate.", "The results are very clear."), ) %>% st_asis()
\clearpage
cols_center()
, cols_left()
, cols_right()
The syntax is to state the default / base alignment for all columns and then pass exceptions to that default setting
Center everything except for
STUDY
(left)DOSE
and SCR
(right)data %>% stable(align = cols_center(STUDY = 'l', .r = "DOSE,SCR")) %>% st_asis()
\clearpage
units <- ys_get_unit(spec, parens = TRUE) stable( data, units = units, ) %>% st_asis()
\clearpage
...
to break; pass cols_break
to alter the break sequencestable( data, cols_rename = vars("Study...Number" = STUDY, "Serum...Albumin" = ALB), units = units ) %>% st_asis()
\clearpage
tmp <- slice(ptdata(), 1:5) xtra0 <- slice(tmp,1) %>% mutate(across(everything(), ~"")) xtra0 xtra1 <- mutate(xtra0, DOSE = "(mg)", N = "(number)", WT = "(kg)") xtra2 <- mutate(xtra0, WT = "[baseline]") xtra <- bind_rows(xtra2,xtra1) xtra
stable(tmp, cols_extra = xtra) %>% st_asis()
\clearpage
$
are "math" and will not be sanitizedptab <- readRDS("datasets/ptab.RDS") ptab
stable( ptab, align = cols_center(Parameter = col_ragged(3), .l = "Symbol"), panel = ".type" ) %>% st_asis()
\clearpage
stable( data, hline_from = "STUDY", ) %>% st_asis()
\clearpage
stable( data, hline_at = c(3,nrow(data))-1, ) %>% st_asis()
\clearpage
clear_grouped_reps
which recursively groups by the column names supplied
and clears the most distant column name in the groupsstable( data, clear_reps = "STUDY", ) %>% st_asis()
\clearpage
tex_bold
will make table cells bold when they match pattern
tex_it
will make table cells italics when they match pattern
clear_rep
and hline_from
to partition the tabletmp <- ptdata() tmp <- mutate(tmp, STUDY = tex_bold(as.character(STUDY)))
stable( tmp, clear_reps = "STUDY", hline_from = "STUDY", ) %>% st_asis()
\clearpage
c(prefix_text = panel_name)
)stable( data, panel = as.panel("STUDY", prefix = "Study number: "), ) %>% st_asis()
\clearpage
stable(data[1:3,], drop = "STUDY,FORM,DOSE") %>% st_asis()
stable(data[1:3,], drop = "SCR,FORM,DOSE", panel = "STUDY") %>% st_asis()
\clearpage
stable( data, span = colgroup("In final model", WT:CRCL), ) %>% st_asis()
\clearpage
stable( data, span = list( colgroup("Meh", DOSE:WT), colgroup("Hrm", AGE:CRCL), colgroup("Huh", ALB:SCR), colgroup("Expert opinion", CRCL:SCR, level = 2) ) ) %>% st_asis()
\clearpage
tag.name
sep
argument; the tag
(common across columns in the
group) forms the spanner titletag.
off of tag.name
dotdata <- readRDS("datasets/with-dots.RDS") head(dotdata, n=2)
stable( dotdata, span_split = colsplit(sep = '.'), ) %>% st_asis()
\clearpage
You can include ...
in the title it will break in to multiple lines. You can
alter the split sequence with the span_title_break
argument (default is ...
) .
See ?tab_spanners
.
This feature is in addition to the functionality allowing you to break column
names (control the split seqence with cols_break
, where default is also ...
).
stable( stdata(), span = colgroup("Final model ... Covariates", WT:SCR), cols_rename = c("Study Protocol ... Number" = "STUDY") ) %>% st_asis()
\clearpage
col_ragged()
alignment to fix the width of a column that has
a lot of text in itdescr is
taking over the tableptable <- readRDS("datasets/ptable.RDS") stable(ptable) %>% st_asis()
descr
to 5 cmstable( ptable, align = cols_center(descr = col_ragged(5)) ) %>% st_asis()
\clearpage
df.total <- readRDS(file = "datasets/with-total.RDS") df.total
stable( df.total, sumrows = sumrow( df.total$STUDY == "all", label = "All Studies", bold = TRUE ) ) %>% st_asis()
\clearpage
stable
output is passed to stable_save()
, the attribute is used
as the output file nametab <- stable(data, output_file = "foo.tex") str(tab)
This can be used to save
stable_save(tab) file.exists("foo.tex")
\clearpage
stable
long <- ptdata() long <- map_dfr(1:2, ~ long) %>% arrange(STUDY,DOSE,FORM)
long %>% 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.2) ) %>% st_asis()
\clearpage
\\normalsize
for the most partdata %>% stable(sizes = tab_size(font = "tiny")) %>% st_asis()
\clearpage
data %>% slice(1:3) %>% stable() %>% st_asis() data %>% slice(1:3) %>% stable(sizes = tab_size(row = 0.9)) %>% st_asis() data %>% slice(1:3) %>% stable(sizes = tab_size(row = 2)) %>% st_asis()
\clearpage
data %>% stable(sizes = tab_size(col = 20)) %>% st_asis()
\clearpage
stable(data) %>% st_asis()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.