In-place Operators for R

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).


Travis build status AppVeyor build status Coverage status

In-place operators for R

This is under development.

Example

# devtools::install_github("privefl/inplace")
library(inplace)
 
address <- data.table::address
mat <- matrix(rnorm(5e7), 1e4)
addr0 <- address(mat)
mat[1:5, 1:5]
 
# copy
system.time(
  mat2 <- mat * 2
)
mat2[1:5, 1:5]
 
# modification in-place
system.time(
  mat %*<-% 2
)
mat[1:5, 1:5]
stopifnot(address(mat) == addr0)
 
## SWEEPS
means <- colMeans(mat)
system.time(
  mat2 <- sweep(mat, 2, means, '-')
)
# modification in-place
system.time(
  sweep2_in_place(mat, means, '-')
)
stopifnot(identical(mat, mat2))
stopifnot(address(mat) == addr0)

Beware

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 %*<-% 2
X
X2

News

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("inplace")

0.1.0 by Florian Privé, 7 months ago


https://github.com/privefl/inplace


Report a bug at https://github.com/privefl/inplace/issues


Browse source code at https://github.com/cran/inplace


Authors: Florian Privé [aut, cre]


Documentation:   PDF Manual  


GPL-3 license


Imports Rcpp

Suggests spelling, data.table, testthat, covr

Linking to Rcpp


See at CRAN