Assigning & function to variable

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Assigning & function to variable

Rainer Krug-3
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


--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      [hidden email]

Skype:      RMkrug

______________________________________________
[hidden email] 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.

attachment0 (504 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Assigning & function to variable

Prof Brian Ripley
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
>
>
>
>
> ______________________________________________
> [hidden email] 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,                  [hidden email]
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Assigning & function to variable

Rainer Krug-3
Prof Brian Ripley <[hidden email]> writes:

> 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 <- `&`
>
Thanks - that works perfectly.

> 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% .

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

>
>
>>
>> Thanks,
>>
>> Rainer
>>
>>
>>
>>
>> ______________________________________________
>> [hidden email] 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.
>>
--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      [hidden email]

Skype:      RMkrug

______________________________________________
[hidden email] 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.

attachment0 (504 bytes) Download Attachment