stdvectors-package: C++ Standard Library Vectors in R

Description Details Author(s) References Examples

Description

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

Details

Package: stdvectors
Type: Package
Version: 0.0.5
Date: 2017-02-20
License: GPL (>= 2)

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

Author(s)

Marco Giuliano

Maintainer: Marco Giuliano <mgiuliano.mail@gmail.com>

References

cpp reference page : http://en.cppreference.com/w/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  # create a stdvector
  sv <- stdvectorCreate('integer')
  # add 100 values to it
  for(i in 1:100){
    # note that sv is modified in-place
    stdvectorPushBack(sv,i)
  }
  # get a normal R vector from the stdvector
  v <- stdvectorToVector(sv)

  ## Not run: 
  
    # check the time difference:
    # the first method takes around 2-3 s
    # the second method takes less than 0.1 s
    system.time({
        v <- integer()
        for(i in 1:100000){
          v[[length(v)+1]] <- i
        }
      }
    )
    system.time({
        v <- stdvectorCreate('integer')
        for(i in 1:100000){
          stdvectorPushBack(v,i)
        }
      }
    )

  
## End(Not run)

stdvectors documentation built on May 1, 2019, 9:18 p.m.