Description Usage Arguments Details Value Author(s) Examples
View source: R/replaceDefault.R
replaceDefault
takes a function and a list of values to replace the default values. In addition it checks that the resulting function is fit for use in other functions, e.g. as cost function in optimiseSD
.
1 | replaceDefault(fun, newDefaults = list(), type)
|
fun |
function |
newDefaults |
|
type |
character string indicating the purpose of the resulting function, e.g. to be used as |
Dependent on the type
, a list of required parameters is generated and compared to the parameters of fun
: all required parameters must exist and all other parameters need to have default values (in the resulting function, when defaults of newDefaults
have been inserted)
"summaryFun.summaryPlumes" (summaryFun
in summaryPlumes
): "x", "weight"
"fun.simulationsApply" (fun
, fun_l
, fun_p
, fun_pl
in simulationsApply
): "x", "nout"
"funR.simulationsApply" (fun_Rp
or fun_Rl
in simulationsApply
): "x", "nout", "weight"
"funRR.simulationsApply" (fun_Rpl
in simulationsApply
): "x", "nout", "weight_l", "weight_p"
"fun_interpolation.interpolate" (fun_interpolation
in interpolate
): "data", "newdata", "y"
"fun.spatialSpread" (fun
in spatialSpread
): "allLocations", "locations"
"fun_R.spatialSpread" (fun_R
in spatialSpread
): "x"
"costFun" (costFun
in optimiseSD
): "simulations", "locations"
"optimisationFun.optimiseSD" (optimisationFun
in optimiseSD
): "simulations", "costFun", "locationsAll", "locationsFix", "locationsInitial", "aimcost", "aimNumber", "nameSave"
"evalFunc.rbga.bin"(evalFunc
in rbga.bin
): "chromosome"
For "fun.simulationsApply"
and "funR.simulationsApply"
the parameter "nout" must exist and have default value.
replaceDefault
checks, if fun
is a function. It does not check if the new defaults have the same class as the old ones.
A list
fun |
function |
accept |
|
Kristina B. Helle, kristina.helle@uni-muenster.de
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # examples with warnings
fun1 = "a"
fun_1 = replaceDefault(fun1)
fun2 = function(x){sum(x)}
fun_2 = replaceDefault(fun2, type = "fun.simulationsApply")
fun3 = function(simulations, locations){1}
# change default of 'simulations'
fun_3 = replaceDefault(fun3, type = "costFun",
newDefaults = list(nout = 1, simulations = 10))
# example without warnings
# (new default values have different class, not tested)
fun6 = function(x = 17, weight = "a", extraWeight = matrix(1:12, nrow = 3)){}
fun_6 = replaceDefault(fun6,
newDefaults = list(weight = 3, extraWeight = "c"),
type = "summaryFun.summaryPlumes")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.