RList

The most common way to pass multiple pieces of data in R is by putting them into a list. If you pass a list from R to D, you need some way to work with that data. If you want to return multiple items from D to R, the only way to do that is with a list.

Those are the only two use cases for this struct.

Constructors

this
this(int n)

Create a new R list with n elements. The length can never be changed. This is a limitation on the R side. All we're doing here is calling Rf_allocVector in the R API to allocate a new list with n elements.

this
this(Robj v, bool u = false)

Call this to work with an existing R list. Creates a new R list with the same number of elements as v.

this
this(string name)

Convenience method that allows you to create an RList from a list in R by passing a string holding the R variable name.

Members

Functions

empty
bool empty()
front
Robj front()

Provided to make the RList a range. That allows iteration using a foreach loop.

opIndex
Robj opIndex(int ii)
Robj opIndex(string name)

Allows access to the elements of an RList by index number or by name. Note that it returns an Robj, which may or may not be protected. This is an example of the intended use case:

opIndexAssign
void opIndexAssign(Robj x, string name)
void opIndexAssign(RMatrix rm, string name)
void opIndexAssign(RVector rv, string name)
void opIndexAssign(RString rs, string name)
void opIndexAssign(string s, string name)
void opIndexAssign(string[] sv, string name)
void opIndexAssign(double v, string name)
void opIndexAssign(double[] vec, string name)
void opIndexAssign(int v, string name)

Can add an element by name. This is the idiomatic way to add elements to a list.

popFront
void popFront()

Provided to make the RList a range. That allows iteration using a foreach loop.

put
void put(Robj x, string name)
void put(Robj x)

Add an Robj to the end of the list and set the name to name. Will throw an error if the RList is full.

robj
Robj robj()

Use this to return an RList to R.

unsafePut
void unsafePut(Robj x, int ii)

If you want to add elements by index. Dangerous because there is nothing to prevent you from overwriting an existing element.

Variables

data
ProtectedRObject data;

Needed for handling protection. You should not need to mess with this unless you know what you're doing. Might be made private in the future.

fillPointer
int fillPointer;

Used to make it more convenient to add new elements by name. Do not touch! Will probably be made private in the future.

length
int length;

Number of Robj held. Cannot be changed.

names
string[] names;

Names of objects. Lists in R can be accessed by name or index.

Meta