Skip to content
Back to formatted view

Raw Message

Message-ID: <4CFD7B5A.5080702@witthoft.com>
Date: 2010-12-07T00:10:02Z
From: Carl Witthoft
Subject: followup to "pass operator to function"

In case anyone even remembers that thread, there was a little problem w/ 
some of the solutions provided because here and there are unary rather 
than binary operators or functions.  So, I took two of the responses and 
fixed them up:

dc<-function(op='+',...) do.call(op,list(...))

or

dcc<-function(op=`+`,...) op(...)  #note the backtick

Note that either of these will work so long as you enter the number of 
required arguments for the operator or function you supply.  Turns out 
they also work just fine if you supply a vector (or vectors, as needed).

And just a reminder about syntax:  dc(,7,6) will execute 7+6


hth

Carl