This function generates a Quarto (.qmd) report based on the provided decision context and summary of APSIMX outputs. It uses an AI language model to interpret the decision information and produce a structured report that includes narrative explanations and R code for visualisation, following a predefined template.

generate_decision_qmd(
  apsimx_file,
  decisions,
  qmd_file,
  decision_type = c("cultivar", "sowing", "nitrogen"),
  use_ai = TRUE,
  use_cache = TRUE
)

Arguments

apsimx_file

Character scalar path to the APSIMX file used in the analysis. This will be referenced in the QMD report.

decisions

List of resolved decision objects containing the decision context, including crop, location metadata, soil conditions, and other relevant information that should be included in the report.

qmd_file

Character scalar path where the generated QMD file will be saved. The function will write the generated content to this file.

decision_type

Character scalar indicating the type of decision to generate the report for. Options are "cultivar", "sowing", or "nitrogen". This will guide the content and structure of the generated report.

use_ai

Logical scalar indicating whether to use AI for generating the QMD content (typically TRUE). If FALSE, the function will not generate content and will currently throw an error, as non-AI generation is not implemented yet.

use_cache

Logical scalar indicating whether to use cached AI responses if available. This can speed up generation if the same prompt has been used before.

Value

Character scalar path to the written output QMD file.

Details

The generated QMD report will be saved to the specified file path. The function ensures that the AI-generated content adheres to strict constraints, relying solely on the provided decision context and summary data without introducing new assumptions or calculations.