I have an ellipsis problem when I use optional arguments in my function definition. To clarify, I define the following functions:
func1 <- function (x) (x-2)^2 func3 <- function (fun, arg.curve.user){ arg.curve.user$expr <- substitute(func1) arg.curve.default <- list(col = "blue", n = 1000, main = "This is a test") arg.curve <- modifyList (arg.curve.default, arg.curve.user) do.call("curve", arg.curve) }
By calling func2, func1 is optimized and is also displayed through a call to func3 (requires the Rsolnp package).
func2 ( lb = 0, ub = 8, n.restarts = 5, n.sim = 10, n = 200, from = 0, to = 8)
But suppose the user made a mistake n.restarts and writes nrestarts :
func2 ( lb = 0, ub = 8, nrestarts = 5, n.sim = 10, n = 200, from = 0, to = 8)
In this case, I expect R to fulfill the following plans to address the lack of n.restarts :
- assigns a default value, i.e. 5, n.restarts as an optional argument
- announces a warning at the end: "nrestarts" is not a graphical parameter
But this does not happen, and R assigns the value n (200) instead of n.restarts !!
Can someone help me fix this problem?
Thank you very much