Learn R Programming

apsimr (version 1.2)

edit_sim_file: Edit an APSIM Module File

Description

APSIM helper files, such as "Soil.xml", have a different format from .apsim files and are therefore handled separately

Usage

edit_sim_file(file, wd = getwd(), var, value, overwrite = FALSE)

Arguments

file
.xml module file to be edited
wd
directory containing the .xml file to be edited; defaults to the current wd
var
vector of variables to be edited
value
list of new values for the specified variables
overwrite
logical; if TRUE the old file is overwritten, otherwise a new file is written

Value

complete file path to edited simulation file is returned as a character string

Details

APSIM uses .xml files to dictate how certain processes are carried out. Similar to edit_apsim this function edits a file that will be used in an APSIM simulation. Unlike edit_apsim this function edits the .xml simulation files. The variables specified by var within the .xml file specified by file in the working directory wd are edited. The old values are replaced with value, which is a list that has the same number of elements as the vector var is long. The current .xml file will be overwritten if overwrite is set to TRUE; otherwise the file file-edited.xml will be created. If the file was successfully edited, then the name of the written file is returned.

Examples

Run this code
## Not run: 
# #The file I want to edit is called "Soil.xml" which is the the directory "~/APSIM"
# simFile <- "Soil.xml"
# apsimWd <- "~/APSIM"
# 
# #I want to change the potential nitrification and N2O from nitrification
# simVar <- c("nitrification_pot", "dnit_nitrf_loss","wfnit_values")
# 
# #Change both to absolute values of random N(0,1)
# simValue <- list(abs(rnorm(1)), abs(rnorm(1)), c(0,2,2,1))
# 
# #Edit Soil.xml without overwriting it
# edit_sim_file(file = simFile, wd = apsimWd, var = simVar, value = simValue, overwrite = FALSE)
# 
# #Passing an .apsim file to edit_sim_file will give a warning and redirect it to edit_apsim
# apsimFile <- "Canopy.apsim"
# apsimValue <- list(c(rep(200, 2), rep(300, 9)), 9, "NSW")
# apsimVar <- c("SoilWater/Thickness", "SoilOrganicMatter/SoilCN", "State")
# edit_sim_file(file = apsimFile, wd = apsimWd, var = apsimVar, value = apsimValue, overwrite = FALSE)
# ## End(Not run)

Run the code above in your browser using DataLab