Skip to contents

Assembles a self-contained Quarto document that imports data and metadata and runs the selected processing steps, in canonical order, using the same function calls and defaults as the package tutorials. This is a pure function (no file I/O, no Shiny) so it can be tested and scripted directly; the interactive build_workflow() app calls it to power its live preview.

Usage

generate_workflow_qmd(spec)

Arguments

spec

A list describing the workflow. Recognised fields:

importer

One of "mrmhub", "masshunter", "skyline", "csv_long", "csv_wide". Default "mrmhub".

data_path

Path to the data file as it should appear in the generated document.

metadata_route

"embedded", "msorganiser", "tables", or "none". Default "embedded".

metadata_path

Path to the metadata file (when not embedded).

steps

Character vector of step ids to include (the ids defined in workflow_steps()).

drift_method

Drift model for the drift step: "gaussian" (default), "spline", or "loess".

ref_qc_types, reference_sample_id

Optional reference QC type(s) and reference sample id for drift/batch/calibration. The corrected feature variable is derived automatically as the highest processing level reached by the selected steps.

column_mapping

Named character vector for importer = "csv_long", mapping canonical names to file columns, e.g. c(analysis_id = "Sample", feature_id = "Compound", feature_area = "Area").

variable_name, analysis_id_col, first_feature_column

Arguments for importer = "csv_wide".

output_xlsx

Path for the exported report. Default "results.xlsx".

formats

Character vector of Quarto output formats, any of "html", "docx", "pdf". "pdf" is rendered sans-serif. Default "html".

save_rds

Logical; also save the object as .rds. Default FALSE.

title

Document title. Default "MRMhub Workflow".

Value

A length-1 character string containing the .qmd source.

Examples

cat(generate_workflow_qmd(list(
  importer = "mrmhub",
  data_path = "MRMhub_demo.tsv",
  steps = c("normalize_istd", "quantify_istd")
)))
#> ---
#> title: "MRMhub Workflow"
#> toc: true
#> execute:
#>   warning: true
#> format:
#>   html: default
#> ---
#> 
#> This workflow was generated by `mrmhub::build_workflow()`. Adjust file paths and parameters as needed, then run each chunk.
#> 
#> ## Setup
#> 
#> ```{r}
#> library(mrmhub)
#> ```
#> 
#> ## Import data
#> 
#> Create the experiment container and import the raw results.
#> 
#> ```{r}
#> mexp <- MRMhubExperiment()
#> mexp <- import_data_mrmhub(mexp, path = "MRMhub_demo.tsv", import_metadata = TRUE)
#> ```
#> 
#> ## Normalize by internal standard
#> 
#> Divide each feature by its assigned internal standard to correct for extraction and injection variability.
#> 
#> ```{r}
#> mexp <- normalize_by_istd(mexp)
#> ```
#> 
#> ## Quantify against internal-standard concentrations
#> 
#> Convert normalized signals to concentrations using the spiked internal-standard amounts.
#> 
#> ```{r}
#> mexp <- quantify_by_istd(mexp)
#> ```
#> 
#> ## Export results
#> 
#> Write the processed results to an Excel report.
#> 
#> ```{r}
#> save_report_xlsx(mexp, path = "results.xlsx")
#> ```