Skip to contents

Converts 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() or rlang::quo()) containing sus_* function calls connected by |> or %>%. Pass NULL to capture from the calling context.

file_path

character(1) - Output file path. Extension informs format detection. Pass NULL to return content without writing to disk.

format

character(1) - One of "script", "rmarkdown", "quarto", or "function". Inferred from file_path extension when possible.

include_metadata

logical(1) - Embed R version, package versions, timestamp, and platform. Default TRUE.

include_validation

logical(1) - Add a validation block (stopifnot

  • NA-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. Default FALSE.

Value

Invisibly, a character vector with the exported file content. Side-effect: writes to file_path when provided.

Formats

"script"

Standalone .R script with header, params block, pipeline execution, validation, and sessionInfo().

"rmarkdown"

.Rmd document with YAML params, setup chunk, pipeline, validation, and optional visualisation section.

"quarto"

.qmd document using Quarto YAML front matter.

"function"

Parametrised .R function 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")
} # }