Macaulay2 » Documentation
Packages » RInterface » RValue
next | previous | forward | backward | up | index | toc

RValue -- evaluate R code

Description

RValue parses and evaluates R code given as a string and returns the result as an RObject.

i1 : RValue "choose(10, 3)"

o1 = [1] 120

o1 : RObject of type double

When given a Sequence, the elements are converted to strings with toString and concatenated before evaluation. This is useful for programmatically constructing R code.

i2 : n = 5

o2 = 5
i3 : RValue("factorial(", n, ")")

o3 = [1] 120

o3 : RObject of type double

The Environment option specifies the R environment in which to evaluate the code.

i4 : env = RObject hashTable {"n" => 10_ZZ, "k" => 3_ZZ}

o4 = <environment: 0x7f009715e6b0>

o4 : RObject of type environment
i5 : RValue("choose(n, k)", Environment => env)

o5 = [1] 120

o5 : RObject of type double

A Macaulay2 hash table specifying values of variables with the variable names given as strings may also be passed to the Environment option.

i6 : env2 = hashTable {"x" => 3}

o6 = HashTable{"x" => 3}

o6 : HashTable
i7 : RValue("x + 5", Environment => env2)

o7 = [1] 8

o7 : RObject of type double

See also

Ways to use RValue:

  • RValue(Sequence)
  • RValue(String)

For the programmer

The object RValue is a method function with a single argument.


The source of this document is in /build/reproducible-path/macaulay2-1.26.05+ds/M2/Macaulay2/packages/RInterface/doc/r-value.m2:46:0.