[R] how to overwrite a Unary operator ?

PO SU rhelpmaillist at 163.com
Fri Oct 17 07:36:57 CEST 2014


Tks for your advice,  let the ++ problem alone, how to write an Unary operator ? Is it permitted in R?
such    as    a<-2 , a%+2%  will let a  be 4 .
I just want to know it , i won't pollute r with it , because i know what is r .  : )








--

PO SU
mail: desolator88 at 163.com 
Majored in Statistics from SJTU




At 2014-10-17 13:09:47, "Rolf Turner" <r.turner at auckland.ac.nz> wrote:
>On 17/10/14 17:29, PO SU wrote:
>>
>> Dear expeRts,
>>    Now i want to know how to implement an Unary operator like  i++ in cpp's  synax form.
>>    e.g.   2++  will let 2 be 3 ,  a<-2 ,a++ ,will let a be 3
>> I tried this :
>>   '%++%'<-function(x){
>>     x<<-x+1
>> }
>> but it have problem, the biggest one is it seems the function need
>> twoparams like a%++%b , how to write a function needing just one param?
>>
>> TKS !
>
>Just ***DON'T***.  The "++" operator is useful only for those wish to 
>write code which is obscure to the point of incomprehensibility.  It 
>makes C and its offspring "write only" languages.
>
>If you are going to use R, use R and don't pollute it with such 
>abominations.
>
>cheers,
>
>Rolf Turner
>
>
>-- 
>Rolf Turner
>Technical Editor ANZJS


More information about the R-help mailing list