I'd like to give a params argument to a function and then attach it so that I can use a instead of params$a everytime I refer to the list element a.
run.simulation<-function(model,params){
attach(params)
#
# Use elements of params as parameters in a simulation
detach(params)
}
Is there a problem with this? If I have defined a global variable named c and have also defined an element named c of the list "params" , whose value would be used after the attach command?
with()
andwithin()
do. In the example given,with()
creates an environment fromparams
and then evaluates the expressionprint(a)
inside that environment. Hence the components ofparams
are visible when the expression is evaluated, without needing toattach()
them. – Packthread