o_assign assigns a variable in Octave.
o_assignin is an alias for o_assign. o_get fetches Octave variables/functions and
possibly rename them on the fly with the provided
argument names when present. Functions are returned as
objects of class ,
that can be called subsequently (see the examples).
o_assign(...) o_assignin(...)
o_get(..., unlist = TRUE, rm.ans = TRUE, pattern)
o_assign , or object names to retrieve from
Octave for o_get.ans should be included in the
result. Default is not to include it unless otherwise
explicitly specified with this argument, or if it is part
of the requested variables in o_assign returns invisibly the names of the
assigned variables. o_get returns a list of the retrieved
variable/object. If unlist=TRUE and a single --
not re-named -- variable/object is requested then only
its value is returned.
[Generated from
Octave-
## directly assign variables o_assign(a=1, b=2, c=matrix(1:9, 3)) # retrieve their values o_get() stopifnot( identical(o_get(), list(a=1, b=2, c=matrix(1:9, 3))) )
## assign a variable for each element in a list x <- list(a=10, b=20, c=matrix(101:109, 3)) o_assign(x) o_get() stopifnot( identical(o_get(), x) )
## assign the content of an environment e <- list2env(setNames(x, paste('env', names(x), sep='_'))) o_assign(e) o_get(pattern="^env_")
#---------- # o_get #---------- o_clear();
# get all currently defined variables o_get()
# by default, the automatic variable `ans` is not returned but might be there # from unstored previous computation o_eval('svd(rand(3,3))') o_get() o_get(rm.ans=FALSE)
# load some variables x <- list(b=1, c=3, d=matrix(1:9, 3)) o_assign(x)
# re-fetch all variables o_get() stopifnot( identical(o_get(), x) )
# only fetch specific variables o_get('b') o_get('b', 'c') # one can rename variables on the fly o_get(a='b', 'c') o_get(c(othername='b')) o_get(c(othername='b', 'c'))
# fetching using a regular expression o_assign( setNames(1:3, paste("test", 1:3, sep='_'))) o_get() o_get(pattern="^test")
# works with functions f <- o_get('svd') f f(matrix(1:9,3)) f(matrix(1:9,3), argout=3)
# an error is thrown in the case of multiple matches (the alternatives are shown) o_clear() o_assign(aaa=1, ab=2) try(o_get('a'))
o_assign assigns the variables using the
arguments' names if present. Variables can also be
specified as a single named list or environment. Single
variable assignments can also be specified as
o_assign('a', 10). See Examples for more
details.