Sourcing Octave/Matlab Files

Description

This function sources an Octave file within the current Octave session. The loaded functions are accessible by subsequent calls of .CallOctave.

Usage

o_source(file = "", text = NULL, sep = ";\n")

Arguments

file
the path to the Octave/Matlab source file -- typically with extension ".m".
text
a character vector containing Octave statements, that are concatenated in a temporary file, which is then sourced. This argument typically enables the evaluation of multiple statements, as opposed to single statement evaluation performed by o_eval.
sep
single character string added as suffix to each element of text. The concatenation of all suffixed element should form a valid Octave block.

Value

None

Octave Documentation for <em>source</em>

 -- Built-in Function: source (FILE)
     Parse and execute the contents of FILE.  This is equivalent to
     executing commands from a script file, but without requiring the
     file to be named 'FILE.m'.

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

Examples


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

## Don't show: 
 o_clear() 
## End Don't show

# source file
mfile <- system.file("scripts/ex_source.m", package='RcppOctave')
o_source(mfile)

# pass multiple statements
o_source(text="a=1;b=3;c=randn(1,5);")
o_get('a','b','c')
## $a
## [1] 1
## 
## $b
## [1] 3
## 
## $c
## [1] -1.2651 -0.6869 -0.4457  1.2241  0.3598

# also works with a character vector of statements
o_source(text=c("a=10;b=30;", "c=randn(1,5)", "d=4"))
o_get('a','b','c', 'd')
## $a
## [1] 10
## 
## $b
## [1] 30
## 
## $c
## [1]  0.4008  0.1107 -0.5558  1.7869  0.4979
## 
## $d
## [1] 4

See also

Other Octave_files: o_addpath, o_inpath