[R] Issue with match.call

2010-10-04 Thread raje...@cse.iitm.ac.in

Hi,

I have a function that I'm writing. The arguments in the function are as follows

RFF-function(qtype, qOpt,...){}
i.e., I have two args that are compulsary and the rest are optional. Now when 
my user passes the function call, I need to see what optional args are defined 
and process accordingly...what I have so far is..

RFF-function(qtype, qOpt,...){
mc - match.call(expand.dots=TRUE)
 }

I need to see what all args have been sent out of
vec-c(flag,sep,dec) and define if-else conditions based on whether they 
have been defined. How do I do this?  
[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Issue with match.call

2010-10-04 Thread Joshua Wiley
Hi,

Something along these lines should get you there:

RFF - function(qtype, qOpt, ...) {
  mc - match.call(expand.dots=TRUE)
  vec - c(flag,sep,dec)
  matchedargs - match(vec, names(mc), FALSE)
}

'matchedargs' will be a vector of the positions in mc where it matched
'vec' (or 0 if it did not).  If you just want to extract the actual
arguments passed afterward, use the [[ extraction operator.

Cheers,

Josh

On Mon, Oct 4, 2010 at 6:45 AM, raje...@cse.iitm.ac.in
raje...@cse.iitm.ac.in wrote:

 Hi,

 I have a function that I'm writing. The arguments in the function are as 
 follows

 RFF-function(qtype, qOpt,...){}
 i.e., I have two args that are compulsary and the rest are optional. Now when 
 my user passes the function call, I need to see what optional args are 
 defined and process accordingly...what I have so far is..

 RFF-function(qtype, qOpt,...){
        mc - match.call(expand.dots=TRUE)
  }

 I need to see what all args have been sent out of
 vec-c(flag,sep,dec) and define if-else conditions based on whether 
 they have been defined. How do I do this?
        [[alternative HTML version deleted]]

 __
 R-help@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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
R-help@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.


Re: [R] Issue with match.call

2010-10-04 Thread Hadley Wickham
 RFF-function(qtype, qOpt,...){}
 i.e., I have two args that are compulsary and the rest are optional. Now when 
 my user passes the function call, I need to see what optional args are 
 defined and process accordingly...what I have so far is..

 RFF-function(qtype, qOpt,...){
        mc - match.call(expand.dots=TRUE)
  }

 I need to see what all args have been sent out of
 vec-c(flag,sep,dec) and define if-else conditions based on whether 
 they have been defined. How do I do this?

I think you'd be much better off defining those as arguments and using
missing(), rather than messing around with match.call (unless there is
a specific reason you need the unevaluated expressions).

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

__
R-help@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.