Wrapping and Defining Octave Functions from R

Description

Wrapping and Defining Octave Functions from R

OctaveFunction objects can be created from existing Octave function using their name, or directly from their Octave implementation. In this case, the Octave code is parsed to extract and use the name of the first function defined therein.

Usage

OctaveFunction(fun, check = TRUE)

S4 (OctaveFunction)
`show`(object)

Arguments

fun
the name of an existing Octave function or, Octave code that defines a function.
check
logical that indicates if the existence of the Octave function should be checked. If function does not exist then, an error or a warning is thrown if check=TRUE or check=FALSE respectively. The existence check can be completly disabled with check=NA.
object
Any R object

Slots

  1. namename of the wrapped Octave function

Examples


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

osvd <- OctaveFunction('svd')
osvd
## <OctaveFunction::`svd`>
osvd(matrix(1:9,3))
##           [,1]
## [1,] 1.685e+01
## [2,] 1.068e+00
## [3,] 5.039e-17

orand <- OctaveFunction('rand')
orand()
## [1] 0.3737
orand(2)
##        [,1]   [,2]
## [1,] 0.2671 0.8031
## [2,] 0.9475 0.6484
orand(2, 3)
##        [,1]    [,2]    [,3]
## [1,] 0.4218 0.05603 0.02797
## [2,] 0.9118 0.92820 0.11203

# From source code
myfun <- OctaveFunction('function [Y] = somefun(x)
    Y = x * x;
    end
')
myfun
## <OctaveFunction::`somefun`>
myfun(10)
## [1] 100