
Export a climasus4r Pipeline as a Reproducible Analytical Pipeline (RAP)
Source:R/sus_rap_export.R
sus_rap_export.RdConverts a climasus4r pipeline expression into a portable, self-contained
artefact - an R script (.R), RMarkdown document (.Rmd), Quarto document
(.qmd), or an encapsulated R function - suitable for sharing, archiving,
and re-execution. The exported file embeds session metadata (R version,
package versions, timestamp, platform), an editable parameters block, and
optional validation checks, following Reproducible Analytical Pipeline
principles.
Usage
sus_rap_export(
pipeline = NULL,
file_path = NULL,
format = c("script", "rmarkdown", "quarto", "function"),
include_metadata = TRUE,
include_validation = TRUE,
include_documentation = c("standard", "minimal", "comprehensive"),
output_type = c("analysis", "dashboard", "report"),
lang = "pt",
overwrite = FALSE
)Arguments
- pipeline
A pipeline expression (created with
quote()orrlang::quo()) containingsus_*function calls connected by|>or%>%. PassNULLto capture from the calling context.- file_path
character(1)- Output file path. Extension informs format detection. PassNULLto return content without writing to disk.- format
character(1)- One of"script","rmarkdown","quarto", or"function". Inferred fromfile_pathextension when possible.- include_metadata
logical(1)- Embed R version, package versions, timestamp, and platform. DefaultTRUE.- include_validation
logical(1)- Add a validation block (stopifnotNA-rate check). Default
TRUE.
- include_documentation
character(1)- Comment density in the exported code:"minimal","standard"(default), or"comprehensive".- output_type
character(1)- Purpose of the document:"analysis","dashboard", or"report". Affects visualisation sections in Rmd/Quarto outputs.- lang
character(1)- Language for comments and messages:"pt"(default),"en", or"es".- overwrite
logical(1)- Overwrite an existing file. DefaultFALSE.
Value
Invisibly, a character vector with the exported file content.
Side-effect: writes to file_path when provided.
Formats
"script"Standalone
.Rscript with header, params block, pipeline execution, validation, andsessionInfo()."rmarkdown".Rmddocument with YAML params, setup chunk, pipeline, validation, and optional visualisation section."quarto".qmddocument using Quarto YAML front matter."function"Parametrised
.Rfunction with Roxygen2 header.
Examples
if (FALSE) { # \dontrun{
pipeline <- quote(
sus_data_import(uf = "SP", years = 2020:2022, system = "SIM-DO") |>
sus_data_clean_encoding() |>
sus_data_filter_cid(cid_group = "respiratory") |>
sus_data_aggregate(by = "month")
)
# Export as R script
sus_rap_export(pipeline, "pipeline_respiratorio.R", lang = "pt")
# Export as Quarto document
sus_rap_export(pipeline, "analise.qmd", format = "quarto",
include_documentation = "comprehensive")
} # }