edit_apsim: Edit an APSIM Simulation

Description Usage Arguments Details Value Examples

Description

This function allows you to edit an APSIM simulation file.

Usage

1
edit_apsim(file, wd = getwd(), var, value, overwrite = FALSE)

Arguments

file

file ending in .apsim to be edited

wd

directory containing the .apsim 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, a new file is written otherwise

Details

The variables specified by var within the .apsim 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 length of the vector var. The current .apsim file will be overwritten if overwrite is set to TRUE; otherwise the file file-edited.apsim will be created. If the file was successfully edited, then the name of the written file is returned.

Value

complete file path to edited .apsim file is returned as a character string

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Not run: 
#The file I want to edit is called "Canopy.apsim" which is in the directory "~/APSIM"
apsimFile <- "Canopy.apsim"
apsimWd <- "~/APSIM"

#I want to change the Thickness of the Soilwater, the SoilCN of the SoilOrganicMatter and
#the state at which the simulation is being run.
apsimVar <- c("SoilWater/Thickness", "SoilOrganicMatter/SoilCN", "State")

#Change SoilWater-Thickness to 200,200,300x9
#Change SoilCN to 10
#Change "State" to "NSW"
apsimValue <- list(c(rep(200, 2), rep(300, 9)), 9, "NSW")

#Edit the apsim file without overwriting it
edit_apsim(file = apsimFile, wd = apsimWd, var = apsimVar, value = apsimValue, overwrite = FALSE)

#Run the edited simulation
apsimExe <-"C:/Program Files (x86)/Apsim75-r3008/Model/Apsim.exe"

results <- apsim(apsimExe, apsimWd, files = "Canopy-edited.apsim")

#Passing a simulation file to  edit_apsim will give you a warning and redirect it to edit_sim_file
simFile <- "Soil.xml"
simValue <- list(abs(rnorm(1)), abs(rnorm(1)), c(0,2,2,1))
simVar <- c("nitrification_pot", "dnit_nitrf_loss","wfnit_values")
edit_apsim(file = simFile, wd = apsimWd, var = simVar, value = simValue, overwrite = FALSE)

## End(Not run)

apsimr documentation built on May 2, 2019, 3:03 a.m.