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

# value(RObject) -- convert R object to Macaulay2

## Synopsis

• Function: value
• Usage:
value x
• Inputs:
• x, ,
• Outputs:
• , the Macaulay2 equivalent of x;

## Description

If possible, the Macaulay2 equivalent of the given RObject is returned.

Note that most R objects are vectors. When a vector has length 1, the corresponding Macaulay2 object is returned as a scalar.

When the input is R's NULL, null is returned.

 i1 : x = RObject null o1 = NULL o1 : RObject of type NULL i2 : value x === null o2 = true

When the input is a logical vector, a Boolean is returned.

 i3 : x = RObject true o3 = [1] TRUE o3 : RObject of type logical i4 : value x o4 = true

When the input is an integer vector, a ZZ object is returned.

 i5 : x = RObject 5 o5 = [1] 5 o5 : RObject of type integer i6 : value x o6 = 5

When the input is a double vector, a RR object is returned.

 i7 : x = RObject (3/2) o7 = [1] 1.5 o7 : RObject of type double i8 : value x o8 = 1.5 o8 : RR (of precision 53)

When the input is a complex vector, a CC object is returned.

 i9 : x = RObject ii o9 = [1] 0+1i o9 : RObject of type complex i10 : value x o10 = ii o10 : CC (of precision 53)

When the input is a character vector, a String object is returned.

 i11 : x = RObject foo o11 = [1] "foo" o11 : RObject of type character i12 : value x o12 = foo

When the input is a vector with more than one element, a List object is returned.

 i13 : x = RObject {1, 3, 5, 7} o13 = [1] 1 3 5 7 o13 : RObject of type integer i14 : value x o14 = {1, 3, 5, 7} o14 : List

When the input is a pairlist (R's linked list type), a Sequence is returned.

 i15 : x = RObject (3, 6, 9) o15 = [[1]] [1] 3 [[2]] [1] 6 [[3]] [1] 9 o15 : RObject of type pairlist i16 : value x o16 = (3, 6, 9) o16 : Sequence

There also exists a list type in R, created by the function list, that may contain elements of of any type, much like Macaulay2 lists. When the input is such a list, a List object is returned.

 i17 : RList = RFunction "list" o17 = RList o17 : RFunction i18 : x = RList(2, 4, 6, 8) o18 = [[1]] [1] 2 [[2]] [1] 4 [[3]] [1] 6 [[4]] [1] 8 o18 : RObject of type list i19 : value x o19 = {2, 4, 6, 8} o19 : List

When the input is a matrix or array, a nested List object is returned. Note that R uses column-major order for matrices, unlike Macaulay2, which uses row-major order. No attempt is made to change the order, unlike new RObject from Matrix, which does do this conversion. For the most part, value and RObject are inverses of one another, but this is an exception.

 i20 : A = random(ZZ^2, ZZ^3) o20 = | 8 3 8 | | 1 7 3 | 2 3 o20 : Matrix ZZ <-- ZZ i21 : x = RObject A o21 = [,1] [,2] [,3] [1,] 8 3 8 [2,] 1 7 3 o21 : RObject of type integer i22 : value x o22 = {{8, 1}, {3, 7}, {8, 3}} o22 : List i23 : A == transpose matrix oo o23 = true

When the input has any names, the elements with names are returned as Option objects.

 i24 : x = RObject {foo => 1, 2, bar => 3} o24 = foo bar 1 2 3 o24 : RObject of type integer i25 : value x o25 = {foo => 1, 2, bar => 3} o25 : List