Reads a template APSIM Next Generation file, applies the resolved decision components needed for simulation setup, and writes the resulting model to a new .apsimx file. The assembly currently applies location metadata, default clock settings, weather, soil, cultivar, sowing, soil water, soil nitrogen, and fertilisation nitrogen in sequence.

prepare_apsimx(decisions, template_file, output_file, overwrite = FALSE)

Arguments

decisions

List of resolved decision objects. This should include at least location, crop, cultivar, sowing, soil_water, soil_nitrogen, and fert_nitrogen in the structure expected by the corresponding apply_*() functions.

template_file

Character scalar path to the APSIM template file.

output_file

Character scalar path to the output .apsimx file.

overwrite

Logical scalar. If FALSE (default), fail when output_file already exists.

Value

Character scalar path to the written output APSIM file.

Examples

if (FALSE) { # \dontrun{
decisions <- list(
  location = list(evidence = list(
    weather = list(file = system.file("examples", "wagga.met", package = "agrillm")),
    soil = list(file = "path/to/soil.apsimx")
  )),
  crop = list(crop = "wheat"),
  cultivar = list(cultivar = "scepter"),
  sowing = list(start = "01-may", end = "07-may"),
  soil_water = list(fraction = 0.5),
  soil_nitrogen = list(value = 50),
  fert_nitrogen = list(value = 80)
)

prepare_apsimx(
  decisions = decisions,
  template_file = system.file("examples", "wheat.apsimx", package = "agrillm"),
  output_file = tempfile(fileext = ".apsimx"),
  overwrite = TRUE
)
} # }