MyNixOS website logo
Description

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:

For an introduction of the package, please read the online vignette

Introduction to the R6DS Package

How to install

You can either install the stable version from CRAN

install.packages("R6DS")

or install the development version from GitHub

devtools::install_github("yukai-yang/R6DS")

provided that the package “devtools” has been installed beforehand.

Get started

After installing the package, you need to load (attach better say) it by running the code

library(R6DS)

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()) ) 
#> [1] "RBST"    "RDeque"  "RDict"   "RDLL"    "RQueue"  "RSet"    "RStack" 
#> [8] "version"

Now you can dive deeply into the package by reading the manual

?R6DS

Enjoy!

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 new function

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

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:

  • rqueue takes 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 rqueue.
  • rlistand rstring are 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.

Metadata

Version

1.2.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows