structs: Sane data structures for R

Description Details Author(s) References See Also Examples

Description

structs provides you with data structures that are similar to data structures commonly found in Python, Ruby, PHP, and other scripting languages. While nearly all of the functionality provided by structs is possible in base R, structs provides a similar look and feel to other languages that many developers are more comfortable using (list.py, dict). structur also provides a set of functions to interact with these data structures. Most of the methods and functions come directly from the Python API. For more informaiton on using structur see below, or visit the github page.

Details

Lists

R has it's own list structure, called list. It's also functions as a sort of dictionary, but it's not exactly clear (especially for first time R users) when and where to use it. list.py provides a more familiar API for those of you coming from Python, Ruby, Javascript, etc. It has an OOP feel and allows methods to be accessed via the $ operator (similiar to . in other OOP langauges).

Dicts

dict is similar to a Python dictionary, a Java HashMap, or a PHP array. It's an abstraction on top of a regular R list that functions as a basic key, value store.

Other functions

zip.tuple similar to zip() in Python
zip.dict similar to dict(zip()) in Python
is.dict check if a data structure is a dict
is.list.py check if a data structure is a list

See http://www.yhathq.com/ for more detials.

Author(s)

Greg Lamp <greg@yhathq.com>

References

http://www.yhathq.com/

Package: structs
Type: Package
Version: 0.1
Date: 2013-08-10
License: FreeBSD

See Also

http://blog.yhathq.com/posts/structs

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
x <- dict()
x["one"] = 1
x["two"] = 2
x["three"] = 3
print(x)
x[iris] = iris
x["iris"] = iris
x["iris"]
x[iris]

y <- list.py(1, 2, 3, 4)
y$append(100)
y$pop()
y <- list.py()
y$append(list.py(1, 2))
y$append(list.py(3, 4))
y$append(list.py(5, 6))
print(y)

y <- list.py(1, 2, 3)
x <- list.py(3, 4, 6)
zip.dict(x, y)
zip.tuple(x, y)

yhat/structr documentation built on May 4, 2019, 2:33 p.m.