Search code examples
roperator-keywordunary-operator

Use 'not' instead of '!' in R


I would like R to be more pythonic. One of the steps for transforming it would be the use of 'not' instead of '!'. I hope this does not need writing of C++ and compiling etc, or does it?

Functionality: "!TRUE" should equal "not TRUE".

If you know where to start, please point me there.


Solution

  • You better embrace the R way. Why all the effort for such a small thing? If you want Python, stick with Python. Besides, it is REALLY common to have ! act as "not" in other programming languages.

    Anyway, this is something that allows the use of "not", but it will involve parentheses (the Arrr! way)

    not <- function(x) { !x }
    
    if (not(FALSE)) { print(1) }
    [1] 1 
    

    In my opinion this is far worse than !.

    And I can hear you thinking "but I would like to have if x is not in y:", but please, that would be the same as suggesting I'd want a way for Python not to need indenting.

    The idea is that you learn a language, you do not change a language to suit an individual's needs. What will happen with others using your code?