Hi all
I think this is a really simple problem but I am struggling to find the best solution. I have a list of parameters to be used across a range of functions, and I'd like to write these functions without repeating that general list (with each function including additional parameters). For example:
# list of parameters
params <- list(x=1,y=2,z=3)
# new function on variables a and b, using constants x, y and z from the params list:
newfun <- function(a,b)
{
return(a*x + y*b + z)
}
# apply new function to input values of a and b, using constant values for x, y and z
newfun(a=10, b=100, params) # error
do.call("newfun", c(list(a=10,b=100),params)) # error
with(params, newfun(a=10, b=100))
I think there's something wrong either with how I'm describing the new function (newfun) or calling the function. After reading this
http://stackoverflow.com/questions/9129673/passing-list-of-named-parameters-to-function
I thought do.call might be the solution, but I get an error message.
Any suggestions?
Thanks! Sinead