View source: R/edit_apsim_xml.R
edit_apsim_xml | R Documentation |
This function allows editing of an APSIM (Classic) simulation xml file.
edit_apsim_xml(
file,
src.dir = ".",
wrt.dir = NULL,
parm.path = NULL,
value = NULL,
overwrite = FALSE,
edit.tag = "-edited",
verbose = TRUE
)
file |
file ending in .xml to be edited |
src.dir |
directory containing the .xml 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 |
parm.path |
parameter path to be edited (see example) |
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. |
verbose |
whether to print information about successful edit |
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
.xml file will be overwritten if overwrite
is set to TRUE
; otherwise the file
‘file’ -edited.xml will be created. If (verbose = TRUE) then the name
of the written file is returned. The function is similar to the edit_sim_file functin in the ‘apsimr’
package, but with the difference that here the xml2 package is used instead.
(when verbose=TRUE) complete file path to edited .xml file is returned as a character string. As a side effect this function creates a new XML file.
This function cannot check whether replacement is of the correct length. Also, there is an inspect equivalent. It is more flexible than ‘edit_apsim’ and (perhaps) similar to ‘apsimr::edit_sim_file’.
## This example changes the RUE values
extd.dir <- system.file("extdata", package = "apsimx")
values <- paste(rep(1.7, 12), collapse = " ")
## Writing to a temp directory, but replace as needed
tmp.dir <- tempdir()
edit_apsim_xml("Maize75.xml",
src.dir = extd.dir,
wrt.dir = tmp.dir,
parm.path = ".//Model/rue",
value = values)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.