[R] Assigning & function to variable

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Feb 21 11:49:03 CET 2014


On 21/02/2014 10:07, Rainer M Krug wrote:
> 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.

Use backticks: see ?Quotes.

link <- `&`

You can also make use of .Primitive.

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

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


>
> Thanks,
>
> Rainer
>
>
>
>
> ______________________________________________
> 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.
>


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list