MyNixOS website logo
Description

C++ Standard Library Vectors in R.

Allows the creation and manipulation of C++ std::vector's in R.

stdvectors

C++ Standard Library Vectors in R

The stdvectors package allows the creation and manipulation of C++ std::vector's in R.
std::vector's are dynamically allocated arrays, which are especially helpful when you need to fill a huge vector (e.g. in a loop) but you don't know the size in advance.

Examples :

  • Create a vector by adding elements one by one :
sv <- stdvectorCreate(type='integer')
for(i in 1:10){
  # yes we're modify the vector in-place !
  stdvectorPushBack(sv,i)
}
  • Turn into an R vector
v <- stdvectorToVector(sv)

Benchmarks :

  • Tested on :
R: 3.3.2 64bit   
OS: Window 10  
CPU: i5 6600K @3.5 Ghz  
RAM: 16 GB
# Note: do not increase this too much, otherwise the first test will take ages!
n <- 150000

# R vector (concatenation)
tm1 <- system.time({
  v <- integer()
  for(i in 1:n){
    v[i] <- i
  }
}
)

# R vector (pre-allocation -> unfair test since the assumption is not knowing the size in advance)
tm2 <- system.time({
  v <- rep.int(NA_integer_,n)
  for(i in 1:n){
    v[i] <- i
  }
}
)

# stdvector
tm3 <- system.time({
  sv <- stdvectorCreate(type='integer')
  for(i in 1:n){
    stdvectorPushBack(sv,i)
  }
  v <- stdvectorToVector(sv)
}
)

> tm1
   user  system elapsed 
  10.84    0.00   10.84 
> tm2
   user  system elapsed 
   0.13    0.00    0.13 
> tm3
   user  system elapsed 
   0.18    0.00    0.19 

As you can see the difference is big, and it becomes bigger and bigger as the number of elements grows.

License

GPL (>= 2)

Metadata

Version

0.0.5

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows