## ----setup-knitr, include = FALSE---------------------------------------------
knitr::opts_chunk$set(comment = "#>", fig.width = 6.5, fig.height = 4,
                      dpi = 100, message = FALSE, warning = FALSE)

library(MRManalyzeR)

## ----install, eval = FALSE----------------------------------------------------
# if(!requireNamespace("BiocManager", quietly = TRUE))
#   install.packages("BiocManager")
# BiocManager::install("MRManalyzeR")

## ----library------------------------------------------------------------------
library(MRManalyzeR)

## ----run-example--------------------------------------------------------------
res <- mrmRunExample(render = FALSE, open = FALSE)
list.files(res$output_directory)

## ----meta-example, echo = FALSE-----------------------------------------------
knitr::kable(data.frame(
  Name        = c("20260505_07", "20260505_08", "20260505_09"),
  Sample_ID   = c("CTRL_1", "CTRL_2", "HDM_1"),
  Include     = c("YES", "YES", "YES"),
  Sample_type = c("Sample", "Sample", "Sample"),
  Treatment   = c("PBS", "PBS", "HDM")))

## ----new-config---------------------------------------------------------------
cfg <- file.path(tempdir(), "project_config.yml")
newConfig(cfg, source = "targetlynx")

## ----show-config, echo = FALSE------------------------------------------------
writeLines(readLines(cfg)[8:26])

## ----run-yaml, eval = FALSE---------------------------------------------------
# res <- runMRManalyzeR(cfg)

## ----returned, eval = FALSE---------------------------------------------------
# res$datasetExperiment   # processed, imputed if replace_MVs was set
# res$measured            # processed, never imputed
# res$stats_tables        # what went into the stats workbook

## ----combine, eval = FALSE----------------------------------------------------
# cfg <- newConfig("combine.yml", template = "combine")
# res <- runMRManalyzeRCombine("combine.yml")

## ----interop, eval = requireNamespace("structToolbox", quietly = TRUE) && requireNamespace("pls", quietly = TRUE)----
library(structToolbox)

de      <- loadDataset(system.file("extdata", "example_synthetic.RDS",
                                   package = "MRManalyzeR"))
samples <- subsetDataset(de, conditions = list(Sample_type = "Sample"))

# structToolbox wants the response as a factor
sm <- as.data.frame(samples$sample_meta)
sm$Treatment <- factor(sm$Treatment)
samples$sample_meta <- sm

M <- model_apply(PLSDA(number_components = 2, factor_name = "Treatment"),
                 samples)
round(as.data.frame(M$scores$data)[1:3, ], 2)

## ----session------------------------------------------------------------------
sessionInfo()

