R6 Reference Class Based Data Structures
Provides reference classes implementing some useful data structures.
The package implements these data structures by using the reference class R6.
Therefore, the classes of the data structures are also reference classes which means that their instances are passed by reference.
The implemented data structures include stack, queue, double-ended queue, doubly linked list, set, dictionary and binary search tree.
See for example <https://en.wikipedia.org/wiki/Data_structure> for more information about the data structures.
R6DS version 1.2.0 (Red DS)
R6DS stands for R6 class based Data Structures. The package provides reference classes implementing some useful data stuctures. They are:
- RStack (stack))
- RQueue (queue))
- RDeque (double-ended queue)
- RDLL (doubly linked list)
- RSet (set))
- RDict (dictionary)
- RBST (binary search tree)
For an introduction of the package, please read the online vignette
How to install
You can either install the stable version from CRAN
or install the development version from GitHub
provided that the package “devtools” has been installed beforehand.
After installing the package, you need to load (attach better say) it by running the code
You can first check the information and the current version number by running
version() #> R6DS version 1.2.0 (Red DS)
Then you can take a look at all the available functions and data in the package
ls( grep("R6DS", search()) ) #>  "RBST" "RDeque" "RDict" "RDLL" "RQueue" "RSet" "RStack" #>  "version"
Now you can dive deeply into the package by reading the manual
Something need to be clarified!
It is quite straightforward to create a new instance of the class in the
package. What you can do, for example, is to use the
rstack <- RStack$new()
and an empty stack (
rstack) will be initialized.
You can push elements into it.
rstack$push(1, 2, 3)
and even heterogeneous elements
rstack$push("Hello world!", list(key=1, val=2), RQueue$new())
Notice that, the last pushed element is an instance of the class
RQueue in the package.
Remember that, in R, only the assignment or pass of an instance of some
reference class is pass-by-reference! In the following sentence,
rstack pops the last stacked element (return and remove its handle in
rstack) and assign it by-reference to
rqueue <- rstack$pop()
And the following assignments are pass-by-value (a copy).
rlist <- rstack$pop() rstring <- rstack$pop()
The difference between the two assignments are:
rqueuetakes over the same memory space with the used-to-be-the-last (but not ever since the pop) element in
rstack, and R did not allocate memory space when creating
rstringare variables with newly allocated memory spaces. As for the list and string elements in
rstack, they have been removed completely.
So the conclusion is that, whether it is a pass-by-value or by-reference depends on the object to be passed, not anything else.
Functions in R6DS
|R6DS||R6DS: provides reference classes implementing some useful data stuctures.|
|version||Show the version number of some information.|
|RDict||The RDict reference class|
|RStack||The RStack reference class|
|RDeque||The RDeque reference class|
|RQueue||The RQueue reference class|
|RDLL||The RDLL reference class|
|RSet||The RSet reference class|
|RBST||The RBST reference class|
Vignettes of R6DS
Last month downloads
|Packaged||2019-05-21 10:53:14 UTC; yyang|
|Date/Publication||2019-05-21 11:00:03 UTC|
Include our badge in your README