Description Details Author(s) References Examples
Allows the creation and manipulation of C++ std::vector's in R.
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.
Marco Giuliano
Maintainer: Marco Giuliano <mgiuliano.mail@gmail.com>
cpp reference page : http://en.cppreference.com/w/
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.