[R] Passing additional arguments through '...'

Charles C. Berry cberry at tajo.ucsd.edu
Fri Jul 17 18:59:10 CEST 2009


On Fri, 17 Jul 2009, escher2079 wrote:

>
> Fair enough. I'm not going to post all the code because it's distracting, but
> the following example function is demonstrative of the problem:
>
> exfun<-function(...){
> print(x)
> }
>
> I'm aware that leaving making the only inputs additional arguments is bad
> form, but this is merely an example. So here if I call exfun as follows:
>
> exfun(x=2)
>
> I get "Error in print(x) : object 'x' not found". I guess this makes sense
> since the additional arguments aren't really meant to be used like that, but
> what I would like to know is how I would access the variable passed in the
> additional arguments in exfun given that I know the name (which I can access
> through sys.call). I hope that was helpful :/. Thanks!


Well, I am still not convinced that you have worked through the code in lm 
and understand what it is doing.

I would use

 	sc <- sys.call()

and then work on sc in the same way that lm works on mf to produce the 
model.frame that it passes to model.matrix()

Note to other readers: the list(...) idiom isn't really appropriate here 
as escher's (original) request was to be able to work around partial 
matching issues when named args are used BEFORE ... in the formals of a 
function and calls are constructed that rely on position taking precedence 
over partial matches in ... .

HTH,

Chuck

>
>
>
>
> Charles C. Berry wrote:
>>
>> I did not follow that.
>>
>> But I might guess that you do not grok what
>>
>>  	mf <- eval(mf, parent.frame())
>>
>> is doing in lm(). If so, then you _really_ need to spend some time working
>> that through before attempting a customized argument matching scheme.
>>
>> In any case, the suggestion to "provide commented, minimal,
>> self-contained, reproducible code" is often helpful to folks who read this
>> list in showing what you intend and provides a basis for discussion - even
>> if your code is incomplete or doesn't do quite what you want it to do.
>>
>>
>> HTH,
>>
>> Chuck
>>
>
> -- 
> View this message in context: http://www.nabble.com/Passing-additional-arguments-through-%27...%27-tp24501159p24537455.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901




More information about the R-help mailing list