## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  echo = TRUE,
  message = FALSE
)

## ----load-package, message=FALSE, warning=FALSE-------------------------------
library(BenchHub)

## ----download-trio------------------------------------------------------------
tempCache <- tempdir()
trio <- downloadSubmissionTrio("D001", cachePath = tempdir())
trio

## ----create-trio, message=FALSE, warning=FALSE--------------------------------
trioA <- Trio$new("figshare:26142922/47361079",
                  evidenceColumns = c("time", "status"),
                  task = "Risk Estimation",
                  metrics = list("Harrell C-index" = harrelCIndexMetric, "Begg C-index" = beggCIndexMetric),
                  cachePath = tempCache)
trioA

## ----load-object--------------------------------------------------------------
exampleEnv <- new.env(parent = emptyenv())
data("lubomski_microbiome_data", envir = exampleEnv, package = "BenchHub")

# Add sample IDs so the evidence matches the dataset rows by name.
names(exampleEnv[["lubomPD"]]) <- rownames(exampleEnv[["x"]])

trioB <- Trio$new(data = exampleEnv[["x"]], evidence = list(`Diagnosis` = list(evidence = exampleEnv[["lubomPD"]], metrics = "Balanced Accuracy")),
                  metrics = list(`Balanced Accuracy` = balAccMetric),
                  datasetID = "lubomski_microbiome")
trioB

## ----custom-loader, eval=FALSE------------------------------------------------
# trioGEO <- Trio$new(
#   "GEO:GSE46474",
#   dataLoader = \(path) Biobase::exprs(GEOquery::getGEO(filename = path)),
#   task = "Rejection Prediction",
#   evidenceLoader = \(path) Biobase::phenoData(GEOquery::getGEO(filename = path))[["procedure status:ch1"]],
#   metrics = list(`Balanced Accuracy` = balAccMetric),
#   cachePath = tempdir()
# )
# trioGEO

## ----add-metric---------------------------------------------------------------
eq <- \(expected, predicted, inequality = FALSE) {
  if (inequality) {
    return(!expected == predicted)
  }

  expected == predicted
}

trio$addMetric("equality", eq)

# Trio also supports passing through arguments to a metric
# Note: parameter names added for clarity
trio$addMetric(
  name = "inequality", metric = eq, args = list(inequality = TRUE)
)

## ----see-metric---------------------------------------------------------------
trio$metrics$inequality

## ----split-function-----------------------------------------------------------
trio$split(y = 1:137, n_fold = 2, n_repeat = 5, seed = 1234, stratify = FALSE)
trio$splitIndices

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

