| Type: | Package | 
| Title: | C++ Standard Library Vectors in R | 
| Version: | 0.0.5 | 
| Date: | 2017-02-20 | 
| Author: | Marco Giuliano | 
| Maintainer: | Marco Giuliano <mgiuliano.mail@gmail.com> | 
| Description: | Allows the creation and manipulation of C++ std::vector's in R. | 
| License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] | 
| Imports: | Rcpp (≥ 0.12.4) | 
| URL: | https://github.com/digEmAll/stdvectors | 
| BugReports: | https://github.com/digEmAll/stdvectors/issues | 
| LinkingTo: | Rcpp | 
| NeedsCompilation: | yes | 
| Packaged: | 2017-02-20 21:42:50 UTC; marco | 
| Repository: | CRAN | 
| Date/Publication: | 2017-02-21 00:14:31 | 
C++ Standard Library Vectors in R
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
  # 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)
std::vector R wrapper
Description
Create and manipulate a C++ std:::vector in R.
Usage
stdvectorCreate(type = "double", reserve = 0L)
stdvectorPushBack(sdv, values)
stdvectorSize(sdv)
stdvectorClear(sdv)
stdvectorToVector(sdv)
stdvectorSubset(sdv,indexes)
stdvectorReplace(sdv,indexes,values)
stdvectorErase(sdv,indexFrom,indexTo)
stdvectorClone(sdv)
is.stdvector(x)
## S3 method for class 'stdvector'
print(x, ...)
## S3 method for class 'stdvector'
toString(x, ...)
Arguments
| type | Character string indicating the type of the vector; possible values:  | 
| reserve | The number of slots to be pre-allocated in the stdvector. | 
| sdv | A stdvector object, as returned by  | 
| ... | optional arguments passed to inner  | 
| x | A stdvector object, as returned by  | 
| values | Values to be appended (in  | 
| indexes | Indexes used to subset the current stdvector, in case of out of bounds indexes an error will be raised. | 
| indexFrom | Used by  | 
| indexTo | Used by  | 
Details
-  stdvectorCreatecreates a stdvector object of the indicated type.
-  stdvectorPushBackappends elements to an existing stdvector (see note fortype='any').
-  stdvectorSizereturns the number of elements of an existing stdvector.
-  stdvectorClearremoves all the elements of an existing stdvector.
-  stdvectorToVectorturns an existing stdvector into an R vector of the type chosen when the stdvector has been created.
-  stdvectorSubsetsubsets an existing stdvector returning an R vector with the values corresponding to the selected indexes.
-  stdvectorReplacereplace the elements atindexespositions with the values invaluesargument (see note fortype='any').
-  stdvectorEraseremove the elements fromindexFromtoindexTopositions.
-  stdvectorClonecreate a deep copy of the stdvector object.
Value
-  stdvectorCreatereturns an object of classstdvector.
-  stdvectorPushBackreturnNULLinvisibly.
-  stdvectorSizereturns an integer equal to the size of thestdvector.
-  stdvectorClearreturnsNULLinvisibly.
-  stdvectorToVectorreturns an R vector of the type chosen when thestdvectorhas been created (type='any'will return a list).
-  stdvectorSubsetreturns an R vector (of the type chosen when thestdvectorhas been created,type='any'will return a list) with the values corresponding to the selected indexes.
-  stdvectorReplacereturnsNULLinvisibly.
-  stdvectorErasereturnsNULLinvisibly.
-  stdvectorClonereturns an object of classstdvectorwhich is the copy of the passed object.
Note
stdvector 
- stdvector objects are treated as references, so if you do - sv2 <- sv1and then you modify- sv2actually also- sv1will be modified. You need to do- sv2 <- stdvectorClone(sv1)to actually create a copy.
-  stdvectorPushBackin case of stdvector oftype='any'will append the element passed in the argumentvaluesas a single new element of the vector, even if it's a list.
-  stdvectorSubsetindexes must be between 1 and the size of the stdvector.
-  stdvectorReplaceindexesandvaluesmust have the same length. In case of stdvector oftype='any'will accept onlyindexesof length one.
References
See http://en.cppreference.com/w/cpp/container/vector
Examples
  # 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)