In object-oriented terminology, each nigs[[i]] is an object, and functions Q , K , etc. are methods that act on the properties of the object w , p , etc. Using the proto package, we install each nigs[[i]] in the proto object, and then update the object as indicated. Note that all methods accept the object as the first argument, therefore, if p is a proto-object containing the Q method, then p$Q(t) means looking at p for Q and then starting it with the arguments p and t , therefore, p$Q(t) coincides with with(p, Q(p, t)) . Thus, we have added an additional first argument for each of the methods below. See the prototype homepage for more details.
library(proto)
EDIT: The second possible project is to create a parent meths object to hold methods, rather than defining them again in each individual proto object. In this case, in each method, we must be sure that we use the properties of the object passed in the first argument, since the methods and properties are now in different objects:
meths <- proto( Q = function(., t) sqrt(1 - (2*.$beta*t+t^2)/.$phi), K = function(., t) .$u*t - .$w*.$Q(t) + .$w, K1 = function(., t) (.$u + .$w * (.$beta+t) / (.$Q(t)*.$phi)), K2 = function(., t) { qt = .$Q(t) (.$w/(qt * .$phi) + .$w * (.$beta+t)^2 / (qt^3 * .$phi^2)) } )
Now the following works by looking at Q in nigs[[1]] , but not detecting it, looking at its parent, meths and starting Q found there. In nigs[[1]]$Q(.1) call implicitly passes nigs[[1]] to Q as its first argument, and we defined all the properties inside the body of Q relative to the first argument, so everything works:
> nigs[[1]]$Q(.1) [1] 0.9587958