to_r {cppcontainers} | R Documentation |
Export data to R
Description
Export C++ data to an R object.
Usage
to_r(x, n = NULL, from = NULL, to = NULL)
Arguments
x |
A |
n |
The number of elements to export. If |
from |
The first value in CppSet, CppMultiset, CppMap, CppMultimap objects to export. If it is not a member of |
to |
The last value in CppSet, CppMultiset, CppMap, CppMultimap objects to export. If it is not a member of |
Details
to_r
has side effects, when applied to stacks, queues, or priority queues. These container types are not iterable. Hence,
to_r
removes elements from the CppStack, CppQueue, and CppPriorityQueue objects when exporting them to R. When n
is specified,
the method removes the top n
elements from a stack or priority queue or the first n
elements from a queue. Otherwise, it removes all
elements. Other container types, like sets, etc., are unaffected.
Value
Returns a vector in case of CppSet, CppUnorderedSet, CppMultiset, CppUnorderedMultiset, CppStack, CppQueue, CppPriorityQueue, CppVector, CppDeque, CppForwardList, and CppList objects. Returns a data frame in case of CppMap, CppUnorderedMap, CppMultimap, and CppUnorderedMultimap objects.
See Also
Examples
s <- cpp_set(11:20)
to_r(s)
# [1] 11 12 13 14 15 16 17 18 19 20
to_r(s, n = 4)
# [1] 11 12 13 14
to_r(s, n = -4)
# [1] 20 19 18 17
to_r(s, from = 14)
# [1] 14 15 16 17 18 19 20
to_r(s, to = 18)
# [1] 11 12 13 14 15 16 17 18
to_r(s, from = 14, to = 18)
# [1] 14 15 16 17 18
m <- cpp_unordered_multimap(c("hello", "hello", "there"), 4:6)
to_r(m)
# key value
# 1 there 6
# 2 hello 4
# 3 hello 5
s <- cpp_stack(11:20)
to_r(s, n = 3)
# [1] 20 19 18
s
# Top element: 17