
Last chance! 50% off unlimited learning
Sale ends in
This function allows editing of an APSIM (Classic) simulation file.
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
)
file ending in .apsim to be edited
directory containing the .apsim file to be edited; defaults to the current working directory
should be used if the destination directory is different from the src.dir
either ‘Clock’, ‘Weather’, ‘Soil’, ‘SurfaceOrganicMatter’, ‘MicroClimate’, ‘Crop’, ‘Manager’, ‘Outputfile’ or ‘Other’
specific soil component to be edited
specific manager component to be edited (not implemented yet)
parameter to be edited
new values for the parameter to be edited
logical; if TRUE
the old file is overwritten, a new file is written otherwise
if the file is edited a different tag from the default ‘-edited’ can be used.
path to the attribute to edit when node is ‘Other’
supply the node postion in the case of multiple simulations such as factorials.
whether to print information about successful edit
check whether vectors are of the correct length
(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.
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.
# NOT RUN {
## 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")
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab