Evaluate an Octave Expression

Description

Evaluates an Octave expression in the current embedded Octave session. The variables assigned in the expression are available for subsequent o_eval calls.

Usage

o_eval(..., CATCH, unlist = TRUE)

Arguments

...
The Octave expression(s) to evaluate, as a character string.
CATCH
The Octave expression(s) to evaluate if the evaluation(s) of ... fails. See section Octave Documentation for more details.
unlist
a logical that specifies it single variables should be returned as a single value (default), or as a list.

Value

the result of the evaluation

Octave Documentation for <em>evalin</em>

 -- Built-in Function: evalin (CONTEXT, TRY)
 -- Built-in Function: evalin (CONTEXT, TRY, CATCH)
     Like 'eval', except that the expressions are evaluated in the
     context CONTEXT, which may be either '"caller"' or '"base"'.

     See also: eval, assignin

[Generated from Octave-3.6.4 on 2014-05-21 11:08:13 ]

Examples


## Don't show: 
# roxygen generated flag
options(R_CHECK_RUNNING_EXAMPLES_=TRUE)
## End Don't show

# assign some variable
o_eval("a=10")
## [1] 10

# retrieve its value in a subsequent call
o_eval("a")
## [1] 10
## Don't show: 
 stopifnot( identical(o_eval("a"), 10) ) 
## End Don't show
o_get('a')
## [1] 10

# use its value
o_eval("b = a^2")
## [1] 100
## Don't show: 
 stopifnot( identical(o_eval("b = a^2"), 100) ) 
## End Don't show

# multiple expression can be evaluated
o_eval(a="10^3", singular="svd(rand(4,4))", random="rand(10, 1)")
## $a
## [1] 1000
## 
## $singular
##        [,1]
## [1,] 2.5279
## [2,] 0.7602
## [3,] 0.4378
## [4,] 0.1092
## 
## $random
##          [,1]
##  [1,] 0.36440
##  [2,] 0.06064
##  [3,] 0.10844
##  [4,] 0.84044
##  [5,] 0.90227
##  [6,] 0.35084
##  [7,] 0.45517
##  [8,] 0.23446
##  [9,] 0.32442
## [10,] 0.06486
# or from a list
l <- list(a="10^3", singular="svd(rand(4,4))", random="rand(10, 1)")
o_eval(l)
## $a
## [1] 1000
## 
## $singular
##        [,1]
## [1,] 2.0231
## [2,] 0.6018
## [3,] 0.2792
## [4,] 0.1155
## 
## $random
##          [,1]
##  [1,] 0.40495
##  [2,] 0.93367
##  [3,] 0.08573
##  [4,] 0.51738
##  [5,] 0.81349
##  [6,] 0.57310
##  [7,] 0.53813
##  [8,] 0.51668
##  [9,] 0.05332
## [10,] 0.80864

# if the evaluation fails then an error is thrown
## Not run:  o_eval("a=svd()") 

# except if argument CATCH is provided
o_eval("a=svd()", CATCH="a=2")
## [1] 2
## Don't show: 
 stopifnot( identical(o_eval("a"), 2) ) 
## End Don't show