How to create a function or statement using a symbol?

I would like to create a function with a character (like ~ ) that works similar to the question mark function.

+4
source share
2 answers

You cannot make something "naked" like ?foo without messing with the C code defining the R syntax. For example, you cannot make [fnord meaningful.

This comes from the definition of the syntax in gram .y in R. sources

 | '~' expr %prec TILDE { $$ = xxunary($1,$2); } | '?' expr { $$ = xxunary($1,$2); } | expr ':' expr { $$ = xxbinary($2,$1,$3); } | expr '+' expr { $$ = xxbinary($2,$1,$3); } 

The second line above defines the syntax ?foo . What exactly are you trying to do?

+6
source

You can create functions and variables with arbitrary names using the back of `.

 `~` <- `+` y <- 5 x <- 10 y ~ x # 15 

I would not bother with ~ , although if you are not going to do statistical modeling ....

+2
source

Source: https://habr.com/ru/post/1493415/


All Articles