Description Usage Arguments Details Value Note References Examples
Create and manipulate a C++ std:::vector in R.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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, ...)
|
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 |
stdvectorCreate
creates a stdvector object of the indicated type.
stdvectorPushBack
appends elements to an existing stdvector (see note for type='any'
).
stdvectorSize
returns the number of elements of an existing stdvector.
stdvectorClear
removes all the elements of an existing stdvector.
stdvectorToVector
turns an existing stdvector into an R vector of the type chosen when the stdvector has been created.
stdvectorSubset
subsets an existing stdvector returning an R vector with the values corresponding to the selected indexes.
stdvectorReplace
replace the elements at indexes
positions with the values in values
argument (see note for type='any'
).
stdvectorErase
remove the elements from indexFrom
to indexTo
positions.
stdvectorClone
create a deep copy of the stdvector object.
stdvectorCreate
returns an object of class stdvector
.
stdvectorPushBack
return NULL
invisibly.
stdvectorSize
returns an integer equal to the size of the stdvector
.
stdvectorClear
returns NULL
invisibly.
stdvectorToVector
returns an R vector of the type chosen when the stdvector
has been created (type='any'
will return a list).
stdvectorSubset
returns an R vector (of the type chosen when the stdvector
has been created, type='any'
will return a list) with the values corresponding to the selected indexes.
stdvectorReplace
returns NULL
invisibly.
stdvectorErase
returns NULL
invisibly.
stdvectorClone
returns an object of class stdvector
which is the copy of the passed object.
stdvector
stdvector objects are treated as references, so if you do sv2 <- sv1
and then you modify sv2
actually also sv1
will be modified. You need to do sv2 <- stdvectorClone(sv1)
to actually create a copy.
stdvectorPushBack
in case of stdvector of type='any'
will append the element passed in the argument values
as a single new element of the vector, even if it's a list.
stdvectorSubset
indexes must be between 1 and the size of the stdvector.
stdvectorReplace
indexes
and values
must have the same length. In case of stdvector of type='any'
will accept only indexes
of length one.
See http://en.cppreference.com/w/cpp/container/vector
1 2 3 4 5 6 7 8 9 | # 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.