knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  echo    = FALSE,
  message = FALSE
)
library(elktoeChemistry)
library(dplyr)
library(gt)
analysis_data  <- readRDS(params$inputs$valve)
dt <-
  analysis_data %>%
  select(
    species, id, site, starts_with("baseline_"), n_annuli
  )
val <- function(x){
  sprintf("%.01f (%.02f)", mean(x, na.rm = TRUE), sd(x, na.rm = TRUE))
}

tab <- 
  dt %>%
  select(species, site, id, starts_with("baseline")) %>%
  distinct() %>%
  group_by(species, site) %>%
  summarise(
    n        = n(),
    weight   = val(baseline_weight),
    # volume   = val(baseline_volume/1000),
    length   = val(baseline_length),
    width    = val(baseline_width),
    height   = val(baseline_weight),
    # n_annuli = val(n_annuli),
    .groups = "keep"
  )

out <- 
  tab %>%
  ungroup() %>%
  gt(
    rowname_col = "site",
    groupname_col = c("species")
  ) %>%
  cols_label(
    n      = "n",
    weight = "Weight (g)",
    length = "Length (mm)",
    width  = "Width (mm)",
    height = "Height (mm)",
  ) %>%
  tab_header(
    title = "Baseline characteristrics",
  )
out %>%
  gtsave("table1.tex", path = "../manuscript/figures/")

# out %>%
#   gtsave("table1.html", path = "../manuscript/figures/")
out


bsaul/elktoeChemistry documentation built on Nov. 17, 2022, 8:10 a.m.