edit_apsim: Edit an APSIM (Classic) Simulation

View source: R/edit_apsim.R

edit_apsimR Documentation

Edit an APSIM (Classic) Simulation

Description

This function allows editing of an APSIM (Classic) simulation file.

Usage

edit_apsim(
  file,
  src.dir = ".",
  wrt.dir = NULL,
  node = c("Clock", "Weather", "Soil", "SurfaceOrganicMatter", "MicroClimate", "Crop",
    "Manager", "Outputfile", "Other"),
  soil.child = c("Metadata", "Water", "Physical", "OrganicMatter", "Chemical",
    "Analysis", "InitialWater", "Sample", "SWIM"),
  manager.child = NULL,
  parm = NULL,
  value = NULL,
  overwrite = FALSE,
  edit.tag = "-edited",
  parm.path = NULL,
  root,
  verbose = TRUE,
  check.length = TRUE
)

Arguments

file

file ending in .apsim to be edited

src.dir

directory containing the .apsim file to be edited; defaults to the current working directory

wrt.dir

should be used if the destination directory is different from the src.dir

node

either ‘Clock’, ‘Weather’, ‘Soil’, ‘SurfaceOrganicMatter’, ‘MicroClimate’, ‘Crop’, ‘Manager’, ‘Outputfile’ or ‘Other’

soil.child

specific soil component to be edited

manager.child

specific manager component to be edited (not implemented yet)

parm

parameter to be edited

value

new values for the parameter to be edited

overwrite

logical; if TRUE the old file is overwritten, a new file is written otherwise

edit.tag

if the file is edited a different tag from the default ‘-edited’ can be used.

parm.path

path to the attribute to edit when node is ‘Other’

root

supply the node postion in the case of multiple simulations such as factorials.

verbose

whether to print information about successful edit

check.length

check whether vectors are of the correct length

Details

The variables specified by parm within the .apsim file specified by file in the source directory src.dir are edited. The old values are replaced with value, which is a list that has the same number of elements as the length of the vector parm. The current .apsim file will be overwritten if overwrite is set to TRUE; otherwise the file ‘file’ -edited.apsim will be created. If (verbose = TRUE) then the name of the written file is returned.

When node equals Outputfile, the editing allows to add variables, but not to remove them at the moment.

Value

(when verbose=TRUE) complete file path to edited .apsimx file is returned as a character string. As a side effect this function creates a new (XML) .apsimx file.

Note

The components that can be edited are restricted becuase this is better in preventing errors of editing unintended parts of the file. The disadvantage is that there is less flexibility compared to the similar function in the 'apsimr' package.

Examples


## This example will read one of the examples distributed with APSIM
## but write to a temporary directory

tmp.dir <- tempdir()

extd.dir <- system.file("extdata", package = "apsimx")
edit_apsim("Millet", src.dir = extd.dir, wrt.dir = tmp.dir, 
           node = "Clock",
           parm = "start_date", value = "01/02/1940")

## Editing all of the KL values for Millet
pp.KL <- inspect_apsim_xml("Millet.apsim", src.dir = extd.dir, 
                  parm = "SoilCrop[8]/KL")
                 
kls <- seq(0.08, 0.2, length.out = 11)

edit_apsim("Millet.apsim", 
           src.dir = extd.dir,
           wrt.dir = tmp.dir,
           node = "Other", 
           parm.path = pp.KL,
           value = kls)
           
## Check that it was properly edited

inspect_apsim("Millet-edited.apsim", 
              src.dir = tmp.dir,
              node = "Soil",
              soil.child = "Water",
              parm = "KL")

              



apsimx documentation built on Sept. 11, 2024, 5:42 p.m.