spread | R Documentation |
Inside a function, a call to spread() will attach to the function environment, sys.frame(), the elements in the list, or of the conversion to list of the object (e.g. named vector or FLPar), so that they be called by name. The function environment will be deleted once the function returns, so those variables won't make it to the environment from which the function was called, or further up in the call stack.
spread(object, FORCE = FALSE)
object |
A named list or vector whose elements are to be loaded into the calling environment. |
FORCE |
Should existing variable with matching names be redefined? |
By default, spread() will not overwrite variables in the function environment with the same name as any list element, unless FORCE=TRUE
Invisibly the names of the variables loaded into the calling environment.
The FLR Team
sys.nframe
# EXAMPLE function
foo <- function (params) {
a <- spread(params)
print(a)
x*y
}
# x and y are accesible to the internal calculation
foo(params=list(x=3.5, y=9))
# Works with FLPar
foo(params=FLPar(x=3L, y=0.99238))
# Elements in object must be named
## Not run: foo(list(3, y=0.99238))
# If a variable is missing from the spread object, function will fail
## Not run: foo(list(x=4))
# Unless the variable is already defined in the calling environment,
# in this case <environment: R_GlobalEnv>
y <- 45
foo(params=list(x=4))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.