View source: R/edit_apsimx_json.R
edit_apsimx | R Documentation |
This function allows editing of an APSIM-X (JSON) simulation file.
edit_apsimx( file, src.dir = ".", wrt.dir = NULL, node = c("Clock", "Weather", "Soil", "SurfaceOrganicMatter", "MicroClimate", "Crop", "Manager", "Report", "Other"), soil.child = c("Metadata", "Water", "SoilWater", "Organic", "Physical", "Analysis", "Chemical", "InitialWater", "Sample"), manager.child = NULL, parm = NULL, value = NULL, overwrite = FALSE, edit.tag = "-edited", parm.path = NULL, root, verbose = TRUE )
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 |
node |
either ‘Clock’, ‘Weather’, ‘Soil’, ‘SurfaceOrganicMatter’, ‘MicroClimate’, ‘Crop’, ‘Manager’, ‘Report’ or ‘Other’ |
soil.child |
specific soil component to be edited |
manager.child |
specific manager component to be edited |
parm |
parameter to be edited |
value |
new values for the parameter to be edited |
overwrite |
logical; if |
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 |
The variables specified by parm
within the .apsimx 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
.apsimx file will be overwritten if overwrite
is set to TRUE
; otherwise the file
‘file’ -edited.apsimx will be created. If (verbose = TRUE) then the name
of the written file is returned.
When node equals Report, the editing allows to add variables, but not to remove them at the moment.
(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.
## This example will read one of the examples distributed with APSIM-X ## but write to a temporary directory tmp.dir <- tempdir() ## Edit Bulk density extd.dir <- system.file("extdata", package = "apsimx") bds <- c(1.02, 1.03, 1.09, 1.16, 1.18, 1.19, 1.20) edit_apsimx("Wheat.apsimx", src.dir = extd.dir, wrt.dir = tmp.dir, node = "Soil", soil.child = "Water", parm = "BD", value = bds, verbose = FALSE) ## Inspect file inspect_apsimx("Wheat-edited.apsimx", src.dir = tmp.dir, node = "Soil", soil.child = "Water") ## To delete the file... file.remove(file.path(tmp.dir, "Wheat-edited.apsimx")) ## Edit the fertilizer amount in 'Maize.apsimx' edit_apsimx("Maize.apsimx", src.dir = extd.dir, wrt.dir = tmp.dir, node = "Manager", manager.child = "SowingFertiliser", parm = "Amount", value = 200, verbose = TRUE) ## Make sure it worked inspect_apsimx("Maize-edited.apsimx", src.dir = tmp.dir, node = "Manager") ## Remove the file file.remove(file.path(tmp.dir, "Maize-edited.apsimx"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.