R has no concept of increment operator (as, for example, ++ in C). However, it is easy to implement them yourself, for example:
inc <- function(x) { eval.parent(substitute(x <- x + 1)) }
In this case, you would call
x <- 10 inc(x)
However, it enters the function overhead, so it is slower than entering x <- x + 1 yourself. If I am not mistaken, an increment operator was introduced to facilitate the work with the compiler, since it can directly convert the code into these machine language instructions.
Grega Kešpret Apr 21 2018-11-11T00: 00Z
source share