edit_apsim_xml: Edit an APSIM (Classic) Simulation auxiliary xml file

View source: R/edit_apsim_xml.R

edit_apsim_xmlR Documentation

Edit an APSIM (Classic) Simulation auxiliary xml file

Description

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

Usage

edit_apsim_xml(
  file,
  src.dir = ".",
  wrt.dir = NULL,
  parm.path = NULL,
  value = NULL,
  overwrite = FALSE,
  edit.tag = "-edited",
  verbose = TRUE
)

Arguments

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 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.

verbose

whether to print information about successful edit

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 .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.

Value

(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.

Note

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’.

Examples


## 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)


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