Macaulay2 » Documentation
Packages » RInterface :: extract or replace parts of RObjects
next | previous | forward | backward | up | index | toc

extract or replace parts of RObjects -- extract or replace parts of R objects

To extract a single element of an RObject, use an underscore, which calls R's [[ operator. Note that R uses one-based indexing.

i1 : x = RObject toList(5..15)

o1 =  [1]  5  6  7  8  9 10 11 12 13 14 15

o1 : RObject of type integer
i2 : x_1

o2 = [1] 5

o2 : RObject of type integer

To extract multiple elements, use square brackets. This calls R's [ operator.

i3 : x[1, 4..8]

o3 = [1]  5  8  9 10 11 12

o3 : RObject of type integer

Parts of an R object may be replaced as well. This only affects the return value. The original object is not modified.

i4 : x_1 = 3

o4 =  [1]  3  6  7  8  9 10 11 12 13 14 15

o4 : RObject of type integer
i5 : x[1..4, 8] = {1, 2, 3, 4, 5}

o5 =  [1]  1  2  3  4  9 10 11  5 13 14 15

o5 : RObject of type integer
i6 : x

o6 =  [1]  5  6  7  8  9 10 11 12 13 14 15

o6 : RObject of type integer