Macaulay2 » Documentation
Packages » RInterface » RObject » value(RObject)
next | previous | forward | backward | up | index | toc

value(RObject) -- convert R object to Macaulay2

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

--error or time limit reached in conversion of output to net: type 'debugError()' to run it again; will try conversion to string

o1 = 

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

--error or time limit reached in conversion of output to net: type 'debugError()' to run it again; will try conversion to string

o3 = 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

--error or time limit reached in conversion of output to net: type 'debugError()' to run it again; will try conversion to string

o5 = 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)

--error or time limit reached in conversion of output to net: type 'debugError()' to run it again; will try conversion to string

o7 = 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

--error or time limit reached in conversion of output to net: type 'debugError()' to run it again; will try conversion to string

o9 = 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

--error or time limit reached in conversion of output to net: type 'debugError()' to run it again; will try conversion to string

o11 = 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}

--error or time limit reached in conversion of output to net: type 'debugError()' to run it again; will try conversion to string

o13 = 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)

--error or time limit reached in conversion of output to net: type 'debugError()' to run it again; will try conversion to string

o15 = 3, 6, 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)

--error or time limit reached in conversion of output to net: type 'debugError()' to run it again; will try conversion to string

o18 = 2, 4, 6, 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

--error or time limit reached in conversion of output to net: type 'debugError()' to run it again; will try conversion to string

o21 = 8, 1, 3, 7, 8, 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}

--error or time limit reached in conversion of output to net: type 'debugError()' to run it again; will try conversion to string

o24 = 1, 2, 3

o24 : RObject of type integer
i25 : value x

o25 = {foo => 1, 2, bar => 3}

o25 : List

Ways to use this method:


The source of this document is in RInterface/doc/value.m2:90:0.