I'd like to write a more-or-less generic caller to targetf
that retains its default parameters.
Suppose we have a provided by some 3rd party library targetf
:
targetf<-function(x=1,...){
print(paste("x =",x))
}
How to write wrapperf
, that will respect targetf
s default arguments, so calling
wrapperf()
would not yield the error message Error in paste("x =", x) : argument "x" is missing, with no default
?
The obvious candidate wrapperf1<-function(x,y) {targetf(x=x)}
doesn't work and fails with wrapperf1()
.
The wrapperf2<-function(...) {targetf(...)}
behaves correctly, but it doesn't work for me, because I only care to pass the x
argument, (and possibly reserve the ...
to other functions in wrapperf
body).
Maybe to solve the issue I'd have to play with ellipsis filtering, which is a terra incognita for me at the moment...
One idea on how to solve the problem: maybe I'd need to create a specially crafted ...
object from scratch in wrapperf
to do pseudo code like this:
wrapperfX<-function(x,y,...)
{
...<-if(missing(x){
list()
}else{
list(x=x)
}
targetf(...)
}
But I have no idea how to even start doing assignments into ellipsis... are the possible at all? I put this question separately on SO: Is it possible to create an ellipsis (…
) object from scratch
Since the problem is still unsolved I decided to post this question to r-help@r-project.org