edit_apsimx_batch: Edit an APSIM-X (JSON) Simulation in Batch mode

View source: R/edit_apsimx_batch.R

edit_apsimx_batchR Documentation

Edit an APSIM-X (JSON) Simulation in Batch mode

Description

This function allows editing of an APSIM-X (JSON) simulation file in batch mode.

Usage

edit_apsimx_batch(
  file,
  src.dir = ".",
  wrt.dir = NULL,
  parms = NULL,
  silent = FALSE,
  verbose = TRUE
)

Arguments

file

file ending in .apsimx to be edited (JSON)

src.dir

directory containing the .apsimx 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

parms

parameter to be edited in the for of ‘key = value’

silent

controls the output of running APSIM at the command line

verbose

whether to print information about successful edit

Details

from hol430

This allows the user to specify an .apsimx file and a config file when running Models.exe. The .apsimx file will not be run but instead, the changes listed in the config file will be applied to the .apsimx file, which will then be written to disk under the same filename.

The config file should contain lines of the form ‘path = value’

e.g.

[Clock].StartDate = 2019-1-20 .Simulations.Sim1.Name = SimulationVariant35 .Simulations.Sim2.Enabled = false .Simulations.Sim1.Paddock.Soil.Thickness[1] = 50 Notes:

Command line arguments should look like: Models.exe file.apsimx /Edit /path/to/config/file.conf

Relative paths will be resolved to the first match. ie [Clock].StartDate will match the first clock found in the file.

Dates can be specified as yyyy-mm-dd or mm/dd/yyyy.

Strings should not be quoted

Array indices will be interpted as 1-indexed (mad face). So the first element in the array should have index 1 in the config file.

The file will be upgraded to the latest file version as part of this process.

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 (JSON) .apsimx file.

Examples


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

tmp.dir <- tempdir()

## Edit InitialResidueMass
extd.dir <- system.file("extdata", package = "apsimx")
parms <- list(`.Simulations.Simulation.Field.SurfaceOrganicMatter.InitialResidueMass` = 600)
edit_apsimx_batch("Wheat.apsimx", src.dir = extd.dir, wrt.dir = tmp.dir, parms = parms)



apsimx documentation built on March 18, 2022, 7:52 p.m.