It provides in-place operators for R that are equivalent to '+=', '-=', '*=', '/=' in C++. Those can be applied on integer|double vectors|matrices. You have also access to sweep operations (in-place).
In-place operators for R
This is under development.
# devtools::install_github("privefl/inplace")library(inplace) address <- data.table::addressmat <- matrix(rnorm(5e7), 1e4)addr0 <- address(mat)mat[1:5, 1:5] # copysystem.time( mat2 <- mat * 2)mat2[1:5, 1:5] # modification in-placesystem.time( mat %*<-% 2)mat[1:5, 1:5]stopifnot(address(mat) == addr0) ## SWEEPSmeans <- colMeans(mat)system.time( mat2 <- sweep(mat, 2, means, '-'))# modification in-placesystem.time( sweep2_in_place(mat, means, '-'))stopifnot(identical(mat, mat2))stopifnot(address(mat) == addr0)
If many names points to the same object, they will be all modified, which is not the default behaviour of base R.
(X <- runif(4))X2 <- X X %*<-% 2XX2