Skip to content

Assigning & function to variable

3 messages · Brian Ripley, Rainer M Krug

#
Hi

I want to assign the function & and | to a variable, because I want to
specify as a function argument if inside the function & or | should be
used.

  link <- &

does not work, and

  link <- "&" 

results in the string "&" being assigned to link.

So how can I assign the logical function to the variable link, so that I
can do

TRUE link FALSE

Thanks,

Rainer
#
On 21/02/2014 10:07, Rainer M Krug wrote:
Use backticks: see ?Quotes.

link <- `&`

You can also make use of .Primitive.
Are you trying to ask how to make 'link' into a binary operator?  You 
cannot: user-defined binary operators are of the form %link% .

  
    
#
Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
Thanks - that works perfectly.
Initially I wanted,  but using the form link(x, y) makes the argument
more powerful as user defined functions can be supplied which return
logical vectors.

Thanks a lot,

Rainer