Learn R Programming

apsimr (version 1.2)

apsim_vector: Edit and Run an APSIM Simulation

Description

This function will edit then run an APSIM simulation. It can be thought of as a vectorized version of apsim.

Usage

apsim_vector(X, exe, wd, vars, to.run, to.edit = to.run, overwrite = FALSE, g)

Arguments

X
N-by-p matrix of inputs with rows corresponding to runs and columns for variables
exe
where to find the APSIM executable
wd
directory where the .apsim file lives and where the results will be saved
vars
names of the variables, must be of the same length as 'X' has columns
to.run
the .apsim file in wd to run
to.edit
the .apsim file or .xml file to be edited
overwrite
logical; passed to the edit_apsim and edit_sim_file functions
g
a function of the output returned by apsim - must give vector or scalar result

Value

a vector of length N

Details

In order to link between the sensitivity package and APSIM, there needs to be a function that can edit then run APSIM that produces a univariate output. The apsim_vector function satisfies these conditions and can return multivariate output if a multivariate sensitivity analysis is of interest. See the examples section or the package vignette for details.

Examples

Run this code
## Not run: 
# meanCowpea<-function(X){
#  return(mean(X$lai_cowpea))
# }
# 
# apsimWd <- "~/APSIM"
# apsimVar <- c(rep("SoilWater/Thickness",11), "SoilOrganicMatter/SoilCN")
# apsimValue <- matrix(c(rep(200, 2), rep(300, 9), 10,
#                        rep(350, 2), rep(350, 9), 5),nrow=2,byrow=T)
# apsimExe <-"C:/Program Files (x86)/Apsim75-r3008/Model/Apsim.exe"
# apsimFile <- "Canopy.apsim"
# 
# #Run APSIM at each new parameter vector specified by apsimVar and only return the mean cowpea value
# uniRes <- apsim_vector(X = apsimValue, exe = apsimExe, wd = apsimWd, vars = apsimVar,
#          to.run = apsimFile, to.edit = apsimFile, g = meanCowpea)
# uniRes
# 
# 
# allCowpea <- function(x){
#  return(x$lai_cowpea)
# }
# 
# #Use allCowpea function to return all the cowpea values
# multiRes <- apsim_vector(X = apsimValue, exe = apsimExe, wd = apsimWd, vars = apsimVar,
#              to.run = apsimFile, to.edit = apsimFile, g = allCowpea)
# multiRes
# ## End(Not run)

Run the code above in your browser using DataLab