next | previous | forward | backward | up | index | toc

# RObject -- R object

## Synopsis

• Usage:
RObject x
• Inputs:
• x, , a Macaulay2 object;
• Outputs:
• , the R equivalent of x;

## Description

An RObject is a SEXP (pointer) to an R object in memory. An RObject may be one of several different types. Note that in R, most objects are actually vectors, and scalars are just vectors of length 1.

RObject is a SelfInitializingType, and so it acts as its own constructor method. When passed a Macaulay2 object as input, the corresponding R object is returned.

Nothing inputs return R's NULL.

 i1 : RObject null o1 = NULL o1 : RObject of type NULL

Boolean inputs return logical vectors.

 i2 : RObject true o2 = [1] TRUE o2 : RObject of type logical

Another logical vector without a Macaulay2 equivalent is NA.

 i3 : NA o3 = [1] NA o3 : RObject of type logical

ZZ inputs return integer vectors.

 i4 : RObject 1 o4 = [1] 1 o4 : RObject of type integer

RR (and QQ) inputs return double vectors.

 i5 : RObject pi o5 = [1] 3.141593 o5 : RObject of type double

CC inputs return complex vectors.

 i6 : RObject ii o6 = [1] 0+1i o6 : RObject of type complex

String (and Symbol) inputs return character vectors.

 i7 : RObject "Hello, world!" o7 = [1] "Hello, world!" o7 : RObject of type character i8 : RObject foo o8 = [1] "foo" o8 : RObject of type character

With a List input, the type of the output depends on the elements of the list. The R function c is used to combine the elements into a vector.

 i9 : RObject {true, false, true, false} o9 = [1] TRUE FALSE TRUE FALSE o9 : RObject of type logical i10 : RObject {2, 4, 6, 8, 10} o10 = [1] 2 4 6 8 10 o10 : RObject of type integer i11 : RObject {0, 1/2, exp 1} o11 = [1] 0.000000 0.500000 2.718282 o11 : RObject of type double i12 : RObject apply(3, k -> exp(2*k*pi*ii/3)) o12 = [1] 1.0+0.0000000i -0.5+0.8660254i -0.5-0.8660254i o12 : RObject of type complex i13 : RObject {"foo", "bar", "baz"} o13 = [1] "foo" "bar" "baz" o13 : RObject of type character

When a Sequence is given as input, a pairlist, a linked list type used by R for function arguments, is returned.

 i14 : RObject (2, 3, 5) o14 = [[1]] [1] 2 [[2]] [1] 3 [[3]] [1] 5 o14 : RObject of type pairlist

When a List or Sequence is given as input and any of its elements are Option objects, then the keys are used as names by R.

 i15 : RObject {foo => 1, bar => 2} o15 = foo bar 1 2 o15 : RObject of type integer i16 : RObject (baz => 3, qux => 4) o16 = $baz [1] 3$qux [1] 4 o16 : RObject of type pairlist

When a Matrix is given as input, an R matrix is returned.

 i17 : A = random(ZZ^2, ZZ^3) o17 = | 8 3 8 | | 1 7 3 | 2 3 o17 : Matrix ZZ <-- ZZ i18 : RObject A o18 = [,1] [,2] [,3] [1,] 8 3 8 [2,] 1 7 3 o18 : RObject of type integer

Each RObject is displayed by calling R's capture.output function.