by_PoolIndex,function,character,character-method {SoilR} | R Documentation |
convert a function f of to f_vec
## S4 method for signature ''function',character,character' by_PoolIndex(obj, poolNames, timeSymbol)
obj |
object of class: |
poolNames |
object of class: |
timeSymbol |
object of class: |
f_vec(vec,t) A new function that extracts the arguments of obj from a complete vector of state variables and the time argument t and applies the original function to these arguments The ode solvers used by SoilR expect a vector valued function of the state vector and time that represents the derivative. The components of this vector are scalar functions of a vector argument and time. It is possible for the user to define such functions directly, but the definition always depends on the order of state variables. Furthermore these functions usually do not use the complete state vector but only some parts of it. It is much clearer more intuitive and less error prone to be able to define functions that have only formal arguments that are used. This is what this method is used for.
leaf_resp=function(leaf_pool_content){leaf_pool_content*4} leaf_resp(1) poolNames=c( "some_thing" ,"some_thing_else" ,"some_thing_altogther" ,"leaf_pool_content" ) leaf_resp_vec=by_PoolIndex(leaf_resp,poolNames,timeSymbol='t') # The result is the same since the only the forth position in the vector leaf_resp_vec(c(1,27,3,1),5)